feat(forms): add addValidators and hasValidators methods to AbstractControl #42838
Conversation
e2edcae
to
f531579
27986b3
to
1aa5c5b
@dylhunn thanks for addressing the feedback |
c.addValidators(Validators.required); | ||
c.addValidators(Validators.required); | ||
expect(c.hasValidator(Validators.required)).toEqual(true); |
AndrewKushnir
Jul 16, 2021
Contributor
I think we'd also need a separate test to verify that adding the same validator twice (or more) doesn't actually add multiple copies.
@IgorMinar Thanks for the comment! |
@petebacondarwin Thanks for the comments!
Fixed!
I went ahead and fixed this -- now, |
acdaa81
to
d5470b7
@dylhunn it'd be nice to mention the addtion of |
@@ -49,7 +49,7 @@ | |||
"master": { | |||
"uncompressed": { | |||
"runtime-es2015": 1150, | |||
"main-es2015": 162346, | |||
"main-es2015": 163066, |
AndrewKushnir
Jul 21, 2021
Contributor
I think this number should be slightly different now (since some common code was moved to helper functions). Could you please reset it back and rerun the CI to see if payload size is over the threshold?
@dylhunn ah, I see. I misread the diff. Removing an already existing API comes with a non-negligible cost, so I recommend against it in this case. Let's keep it as is in the PR. thank you |
0ce5b9d
to
cd145c2
…ethods (for both sync and async) Several new functionalities are possible with this change: the most requested is that callers can now check whether a control has a required validator. Other uses include incrementally changing the validators set without doing an expensive operation to reset all validators. Closes #13461.
hy guys , |
@khodabandelu extra APIs added in this PR support any validators (built-in as well as custom ones). |
Delicious! Thank you very much for this |
Is it possible to backport it to 12.x branch? Please! |
@e-oz This is available in 12.2 and will not be backported further as it's a feature. |
@JoostK then it's just not mentioned in the changelog :) Thank you for the good news |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #13461
It is currently not possible to modify the validator set on a FormControl, or check for a particular validator's presence.
What is the new behavior?
Add getValidators and hasValidators methods (for both sync and async) to the FormControl API, enabling vaioud use cases in a longstanding issue.
Several new functionalities are possible with this change: the most requested is that callers can now check whether a control has a required validator. Other uses include incrementally changing the validators set without doing an expensive operation to reset all validators.
Does this PR introduce a breaking change?
Other information
Closes #13461.