-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Description
Which @angular/* package(s) are relevant/related to the feature request?
forms
Description
Here is my use case. I have a form group with form control and a form array of form groups. I have validation rules that need access to both form control and form array to validate. I also have server side code that may add an item into an array. When server request completes, I want to patch the entire form, then trigger business rules (validation rules). This is currently not possible if number of items in an array that comes from the server is larger than the number of items in the corresponding form array. PatchValue fired on the root form will throw an error if number of items in json array and FormArray is not the same. Hence, I have to adjust the number of items. However, both push and removeAt methods on FormArray do no support onlySelf option, like patchValue does. Neither does setControl on FormGroup, which I could use to replace entire FormArray.
Proposed solution
Add onlySelf option to:
FormGroup's methods
- setControl
- removeControl
FormArray's methods
- push
- removeAt
- insert
- setControl
All of them already have options: {emitEvent?: boolean}, I am proposing to change that to options: {emitEvent?: boolean, onySelf? boolean} When onlySelf is true, do not trigger validation for the parent just like in patchValue
Thank you!
Alternatives considered
Replacing entire control, but that will trigger parent validation. Disabling the control, but that seems ugly.
Thank you!