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

Overriding Angular's email validator #5

Closed
sebastian-zarzycki-apzumi opened this issue Feb 1, 2018 · 6 comments
Closed

Overriding Angular's email validator #5

sebastian-zarzycki-apzumi opened this issue Feb 1, 2018 · 6 comments
Labels

Comments

@sebastian-zarzycki-apzumi

It seems that newer versions of Angular also have email validator. This library also offers email validator that seems to be more tight and restrictive (which is good). I wonder how it works, though, as the selector seems to be exactly the same. Does Angular run both validators under the same name, or is it overridden somehow (because declared later?)

@rsaenen
Copy link
Owner

rsaenen commented Feb 2, 2018

Angular directive selector:

selector: '[email][formControlName],[email][formControl],[email][ngModel]'

Custom ng4-validators directive selector:

selector: '[email][formControlName],[email][formControl],[email][ngModel]',

So it both has the same selector, I don't check if the custom validator override angular validator since angular 5 release.

I'll check this behavior, but I guess it's better to rename the custom directive selector to avoid issue.

@sebastian-zarzycki-apzumi
Copy link
Author

I would think so, yes, it's probably better to rename.

But, apart from that, I'm a little bit confused as to how this override works, and whether it allows the previous validator run in parallel, or not.

@rsaenen
Copy link
Owner

rsaenen commented Feb 2, 2018

I think there's no override but just javascript runs both and the result is given from the last executed validator.

To override default validator, I guess the custom has to implement an interface like EmailValidatorInterface but without I don't guess that is possible.

@sebastian-zarzycki-apzumi
Copy link
Author

Yeah, the "last executed" part interests me. What is the order? Is it always Angular first, then whatever's declared later? Just curious. Sorry, this probably isn't a bug request anymore. Just worth changing that email validator to avoid confusion.

@rsaenen
Copy link
Owner

rsaenen commented Feb 8, 2018

I'am unable to publish a new version for now, see angular/cli#9549.
I won't publish without run tests.

@rsaenen
Copy link
Owner

rsaenen commented Feb 9, 2018

Released with 5.0.1

@rsaenen rsaenen closed this as completed Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants