Skip to content

Commit d169105

Browse files
author
Martynas Žilinskas
committed
Updated actions. Added emit action in method TouchFields.
1 parent 9dadb13 commit d169105

File tree

2 files changed

+25
-32
lines changed

2 files changed

+25
-32
lines changed

packages/simplr-forms/src/actions/form-store.ts

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ export abstract class FormAction {
1010
}
1111
}
1212

13+
export abstract class FieldAction extends FormAction {
14+
constructor(formId: string, protected fieldId: string) {
15+
super(formId);
16+
}
17+
18+
public get FieldId() {
19+
return this.fieldId;
20+
}
21+
}
22+
1323
export class StateChanged extends FormAction { }
1424

1525
export class FieldRegistered extends FormAction {
@@ -42,36 +52,14 @@ export class FieldsArrayRegistered extends FormAction {
4252
}
4353
}
4454

45-
export class ValueChanged extends FormAction {
46-
constructor(protected formId: string, private fieldId: string) {
47-
super(formId);
48-
}
49-
50-
public get FieldId(): string {
51-
return this.fieldId;
52-
}
53-
}
54-
55-
export class FieldPropsChanged extends FormAction {
56-
constructor(protected formId: string, private fieldId: string) {
57-
super(formId);
58-
}
55+
export class ValueChanged extends FieldAction { }
5956

60-
public get FieldId(): string {
61-
return this.fieldId;
62-
}
63-
}
57+
export class FieldPropsChanged extends FieldAction { }
6458

6559
export class FormPropsChanged extends FormAction { }
6660

67-
export class FormDisabled extends FormAction {
68-
constructor(protected formId: string) {
69-
super(formId);
70-
}
71-
}
61+
export class FormDisabled extends FormAction { }
7262

73-
export class FormEnabled extends FormAction {
74-
constructor(protected formId: string) {
75-
super(formId);
76-
}
77-
}
63+
export class FormEnabled extends FormAction { }
64+
65+
export class FieldTouched extends FieldAction { }

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,13 @@ export class FormStore extends ActionEmitter {
380380
}
381381

382382
public TouchFields(fieldsIds?: string[]): void {
383+
if (fieldsIds == null) {
384+
fieldsIds = this.state.Fields.keySeq().toArray();
385+
}
386+
383387
this.State = this.State.withMutations(state => {
384-
if (fieldsIds == null) {
385-
fieldsIds = state.Fields.keySeq().toArray();
386-
}
387388

388-
fieldsIds.forEach(fieldId => {
389+
fieldsIds!.forEach(fieldId => {
389390
const fieldState = state.Fields.get(fieldId);
390391

391392
if (fieldState != null) {
@@ -397,6 +398,10 @@ export class FormStore extends ActionEmitter {
397398

398399
return this.RecalculateDependentFormStatuses(state);
399400
});
401+
402+
fieldsIds.forEach(fieldId => {
403+
this.emit(new Actions.FieldTouched(this.FormId, fieldId));
404+
});
400405
}
401406

402407
public async ValidateForm(validationPromise: Promise<never>): Promise<void> {

0 commit comments

Comments
 (0)