-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Validators.email should allow null/empty values #16183
Comments
+1
|
There is a pull request for this #16902 |
A workaround in template driven forms (set [email] to false, when value is empty. Ensure to initialize the model value with an empy string):
|
Please fix this for 5.0, since it's a breaking change, otherwise we're going to have to wait for 6 more months and it will be even more painful. |
@rehbein-dieter Nice simple workaround. |
@rehbein-dieter Thanks for the simple workaround. Do you get a console error when you use it though? I get the following error when I leave the field (empty) then go back and add a character. ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'null'. Current value: 'true' |
@rehbein-dieter Nice workaround. Thank you very much !!! |
@rehbein-dieter or anyone else, is there a similar workaround for when you're using reactive forms e.g.:
|
@jloosli A workaround for both types of forms is to simply wrap is in your own custom validator, check the special case and feed the control to |
For what it's worth, as a workaround, I add and remove the email validator based on whether or not the value is empty:
|
For reactive forms this validator works for me:
|
@Toxicable @kara can we get this fixed before v6 is released since it is a breaking change? |
for anyone else wanting a workaround for this, declare a local variable then in your form group dont use email and use a pattern |
Fixed by #20869, which has landed in |
Working with version 5.X , I'm using the following validator:
|
Fixed in 140e7c0 |
Just a workaround |
@davidshepherd7 Thanks Bro |
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. |
I'm submitting a ... (check one with "x")
Current behavior
Controls using the email validator are invalid if no value is present.
Expected behavior
The email validator should allow null/empty values.
Minimal reproduction of the problem with instructions
http://plnkr.co/edit/tsQ3C5tg3ba9xYAWHdLO?p=preview
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
Angular version: 4.x.x
Browser: all
Language: all
The text was updated successfully, but these errors were encountered: