I have the following issue:
I have an Angular FormGroup defined in one of my angular components, which has several FormControl-s in it, displayed using Angular Material. Every a certain input value changes, I reset this form, creating a new instance of FormGroup, and assign it to the same variable, in the following manner:
this.sampleForm = this.formBuilder.group({
'samplePropertyName': new FormControl(
{ value: this.dataVo.samplePropertyName, disabled: !this.isEditable() },
[...]
},
{ updateOn: 'blur' }
);
This is working very well, in parts. The visible fields all get updated with their proper new value. However, this is not the case with the disabled state. Every field that is not a base input field, but a unique field type from Angular Material, such as mat-select or mat-datepicker, fails to properly update its disabled state.
I have tried enabling and disabling the formGroup itself, without success. Neither did calling changeDetectorRef work. Is the only solution to not assign a new form instance, but rather, update the existing formcontrols one by one? I really hope this is not the case, as this form has a fair number of fields.
disable()
andenable()
methods on each formControl, instead of setting it in the FormControl constructor ? This way components should catch the event... If it doesn't work, try to call them inside asetTimeout(() => xxx, 0)
to make it async ? – Randomthis.mainFormGroup.get('newFormArrayControl').disable();
– Srikar Phani Kumar Marti