Skip to content
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

Interoperability with NG_VALIDATORS #17

Open
ShacharHarshuv opened this issue Oct 31, 2024 · 0 comments
Open

Interoperability with NG_VALIDATORS #17

ShacharHarshuv opened this issue Oct 31, 2024 · 0 comments

Comments

@ShacharHarshuv
Copy link
Owner

This feature in Angular's ReactiveForms enables you to create a built-in validator inside a custom form control, which will cause it to be invalid and/or have errors. This uses setValidators behind the scenes.

There are a few issues with this approach in ReactiveForms:

  • Using setValidators does not automatically run the validations again, so the control might not get invalid even though it should be.
  • If the custom control component was destroyed, the validator is removed. If the control was previously invalid, it might be become valid again when running update value and validity. This is usually not the desire behavior, since this case occurs usually when you hide views from the user, and you don't really want logic to change as a result. (For example, if you have a form that is divided to multiple routes)

To support NG_VALIDATOR, we'll have an internal function that can add errors (not validators) to the validation state of the control.

We'll create FormCustomValidatorDirective that will use this internal function in hook into the NG_VALIDATORS provider to make this work.

[!question]

  • Do we want this only for the compatibility layer, or do we also want to supply our own API for this?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant