Let's say we have myFormGroup
which is initialized via FormBuilder:
this.myFormGroup = this.fb.group(
{
field1: ['', SomeValidator1],
field2: ['', AnotherValidator2],
field3: [''],
...
}
);
I'm aware that we can disable particular form control, for instance:
fb.control({value: 'my val', disabled: true});
Of course I can use this syntax in my example and mark as disabled every single control in the group. But the form group might have a lot of controls.
So the question - is there any way to disable entire FormGroup/FormArray while creating (not after) it via FormBuilder?
p.s. The reason I'm asking this question is because I need conditionally initialize form group with active or disabled fields for different kind of user privileges.
this.myFormGroup.disable()
. See the Profile Editor in this stackblitz. I don't know if it can be done when creating the group however. – Dabneythis.fb.group(...)
. – Dabney