-
Notifications
You must be signed in to change notification settings - Fork 25.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(forms): easier updating of validators on existing controls #9516
feat(forms): easier updating of validators on existing controls #9516
Conversation
@@ -100,6 +100,13 @@ export abstract class AbstractControl { | |||
|
|||
get pending(): boolean { return this._status == PENDING; } | |||
|
|||
setValidators(newValidator: ValidatorFn|ValidatorFn[]) { | |||
let newValidators = !Array.isArray(newValidator) ? [newValidator] : <ValidatorFn[]>newValidator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you could use coerceToValidator
here?
this.validator = coerceToValidator(newValidator);
If there is a way to set the validator, seems like there should be a way to set and clear async validators as well. Is there a reason that wasn't added? |
lint fix async d test test
@kara That is a good point. I have added async counter parts and addressed your other comments as well, Thanks! |
Thanks for the PR! LGTM. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x")
This will add support for setting and clearing validators on exiting controls. It's already possible to do this by manipulating the
.validator
property on the control, but I am proposing this as an enhancement of the existing API.The use case is dynamic forms where user actions in the form might require validation rules on any given control to change dynamically. The goal is to make the validator updates easier.
Does this PR introduce a breaking change? (check one with "x")
If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...
Other information: