question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation classes not added using type attribute

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
HauntedSmorescommented, Nov 22, 2016

@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

0reactions
angular-automatic-lock-bot[bot]commented, Sep 10, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found