Skip to content

Commit 9f7c2b5

Browse files
authored
Merge pull request #136 from shajz/fix.markAllAsDirty
2 parents 45cfe2b + 175b7a6 commit 9f7c2b5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

libs/reactive-forms/src/lib/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,5 @@ export function controlErrorChanges$(
134134
export function markAllDirty(control: AbstractControl): void {
135135
control.markAsDirty({ onlySelf: true });
136136

137-
(control as any)._forEachChild((control: any) => control.markAllAsDirty?.());
137+
(control as any)._forEachChild((control: any) => control.markAllAsDirty?.() || control.markAsDirty({ onlySelf: true }));
138138
}

libs/reactive-forms/src/lib/form-group.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ describe('FormGroup Functionality', () => {
196196
expect(spy).toHaveBeenCalledWith(false);
197197
});
198198

199+
function areAllAllChildrenDirty(control: AbstractControl) {
200+
expect(control.dirty).toBe(true);
201+
(control as any)._forEachChild((control: AbstractControl) => areAllAllChildrenDirty(control));
202+
}
203+
204+
it('should markAllAsDirty', () => {
205+
const control = createGroup();
206+
207+
jest.spyOn(control, 'markAsDirty');
208+
control.markAllAsDirty();
209+
expect(control.markAsDirty).toHaveBeenCalled();
210+
areAllAllChildrenDirty(control);
211+
});
212+
199213
it('should reset', () => {
200214
const control = createGroup();
201215
jest.spyOn(control, 'reset');

0 commit comments

Comments
 (0)