Skip to content

Commit 1fc36e5

Browse files
Pristine in form-store implemented.
1 parent 423d3ff commit 1fc36e5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/simplr-forms-core/src/stores/form-store.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,29 @@ export class FormStore extends ActionEmitter {
179179
public UpdateFieldValue(fieldId: string, newValue: FieldValue): void {
180180
this.State = this.State.withMutations(state => {
181181
const fieldState = state.Fields.get(fieldId);
182+
const fieldPristine = (newValue === fieldState.InitialValue);
182183
state.Fields = state.Fields.set(fieldId, fieldState.merge({
183-
Value: newValue
184+
Value: newValue,
185+
Pristine: fieldPristine
184186
} as FieldState));
187+
188+
if (!fieldPristine) {
189+
state.Form = state.Form.merge({
190+
Pristine: false
191+
} as FormState);
192+
} else {
193+
let allFieldsPristine = true;
194+
state.Fields.forEach(field => {
195+
if (field != null && !field.Pristine) {
196+
allFieldsPristine = false;
197+
return false;
198+
}
199+
});
200+
201+
state.Form = state.Form.merge({
202+
Pristine: allFieldsPristine
203+
});
204+
}
185205
});
186206

187207
this.emit(new Actions.ValueChanged(fieldId, newValue));

0 commit comments

Comments
 (0)