-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Description
Which @angular/* package(s) are the source of the bug?
forms
Is this a regression?
Yes
Description
I have recently migrated from Angular 9 to Angular 12 and observing one issue related to form control while using ReactiveFormsModule.
The layout is like the page has a dropdown selection and multiple input boxes. And the behavior is if I change the value from dropdown it populates the values of the input box based on the model.
On selecting dropdown value, we are subscribing to value Changes and setting input box values using patchValue() method. I am also using updateValueAndValidity() to update the respective values. Below is the code for reference
toggleControls(show: boolean, formMeta: object, data?: { [key: string]: string }) {
Object.keys(formMeta).forEach((formName) => {
if (!show) {
this.form.removeControl(formName);
return;
}
this.form.addControl(formName, formMeta[formName]);
this.form.get(formName).patchValue(data[formName]);
});
this.form.updateValueAndValidity();
}
Issue:
using patchValue and updateValueAndValidity() is not updating the value of the form controls, and new set value is not getting reflected in the UI as well.
Note: If I manually trigger changeDetection after updateValueAndValidity(), the behavior works as expected.
Question: This behavior was working fine in Angular 9 and observing this issue after migrating to 12. Is there any change recently related to form value update and any alternative solution without using changeDetection..?
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version
)
No response
Anything else?
No response