Skip to content

Commit

Permalink
fix(core): emit valueChanges when FormControl value changes (#3079)
Browse files Browse the repository at this point in the history
fix #3076
  • Loading branch information
aitboudad committed Dec 6, 2021
1 parent 9c8c3ea commit 4bd37b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/core/src/lib/extensions/field-form/utils.spec.ts
Expand Up @@ -146,6 +146,24 @@ describe('registerControl', () => {
expect(spy).toHaveBeenCalledWith({ foo: null });
subscription.unsubscribe();
});

it('should emit valueChanges when FormControl value changes', () => {
const field = {
key: 'foo',
form: new FormGroup({}),
formControl: new FormControl(),
parent: { model: { foo: 'test' } },
};

const spy = jest.fn();
const subscription = field.formControl.valueChanges.subscribe(spy);

registerControl(field);

expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith('test');
subscription.unsubscribe();
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/src/lib/extensions/field-form/utils.ts
Expand Up @@ -81,7 +81,7 @@ export function registerControl(field: FormlyFieldConfigCache, control?: any, em
const paths = getKeyPath(field);
const value = getFieldValue(field);
if (!(isNil(control.value) && isNil(value)) && control.value !== value && control instanceof FormControl) {
control.patchValue(value, { emitEvent: false });
control.patchValue(value);
}

for (let i = 0; i < paths.length - 1; i++) {
Expand Down

0 comments on commit 4bd37b8

Please sign in to comment.