-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
#🚀 feature request
Relevant Package
@angular 5+
Description
In an angular form, I have one control ("first") with 2 custom validators on it.
One of the validators is an async validator that goes to the server to check validation of the field (needs to be chcked with the DB).
this.mainForm.controls['first'].setAsyncValidators([customAsyncValidator()]);
this.mainForm.controls['first'].setValidators([customValidator(this.mainForm.controls['second'])]);
On an update of a different field in the form ("second"), I need to run the customValidator on the "first" control, as the "customValidator" validates the value depending on what is the value in the "second" control.
On the blur of "second" control, I just validate the first one.
`this.mainForm.controls['first'].updateValueAndValidity();`
What's not good in the above solution, is that it executes all the validators of the "firts" control, including the async validator which really takes some time and not necessary in that case (only when the value in the "first" control is being changed).
What I wondered - Is there any way to excecute not all validators of a control, but just some of them?
Describe the solution you'd like
Need a way to execute only some validators on a form control
something like this:
`this.mainForm.controls['first'].updateValueAndValidity([customValidator,...])`
Describe alternatives you've considered
I can remove the validators that I don't need to check now from the control before calling the updateValueAndValidity and re-assign them after calling it.