Validation classes not added using type attribute
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => search github for a similar issue or PR before submitting
[ x ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
When using validation offered by the type attribute on an input element, such as , Angular 2 does not add the proper ng-invalid class when the browser sees the input as invalid.
Expected behavior
ng-invalid and ng-valid classes should be added appropriately when a user’s input does not match the pattern defined by HTML5 type attribute. Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
I believe it is best practice now to use type attributes offered by HTML5 to validate user input before submission.
Please tell us about your environment:
OSX, Brackets IDE, Angular CLI
- Angular version: 2.0.X
2.0.0
- Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
All browsers
- Language: [all | TypeScript X.X | ES6/7 | ES5] Typescript
- Node (for AoT issues):
node --version
=
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
input-validation-error class not added to custom HtmlHelper ...
When this error is added, it should add the input-validation-error class to the input, but it doesn't. I cannot get it to work....
Read more >Constraint validation - HTML: HyperText Markup Language
By setting values on validation-related attributes, allowing basic constraints to be described in a simple way, without the need for JavaScript.
Read more >7 Approaches to Validate Class Attributes in Python
In this article, I want to demonstrate 7 out of many options to validate class attributes using either Python built-in modules or ...
Read more >Validation · Bootstrap v5.0
Bootstrap scopes the :invalid and :valid styles to parent .was-validated class, usually applied to the <form> . Otherwise, any required field without a...
Read more >Model validation in ASP.NET Core MVC | Microsoft Learn
The following example from the sample app shows a model class that is annotated with validation attributes. The [ClassicMovie] attribute is ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pkozlowski-opensource Sorry, I just havnt had time to make a reproduction. Its really simple though - Angular 2 puts classes on form input elements based on their validity (ng-prestine, ng-valid, ng-invalid, etc.). This works when you set things like required and pattern attributes. It has recently been confirmed by a dev from Google over at the gitter server that Angular does not consider the type attribute (type email, tel, etc.) when it adds its validation classes.
If you put an input element with type=“email” and enter an email that the browser sees as invalid, angular will not add the ng-invalid class correctly
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.