Entering invalid value in template drive form showing valid status
See original GitHub issueBug Report
Affected Package
The issue is caused by package @angular/formsIs this a regression?
No
Description
When we have min validator on input element and entering invalid character sets formControl valid status to true.
Minimal Reproduction
Reproductionhttps://stackblitz.com/edit/angular-ivy-g1zbbb?file=src/app/app.component.html
Your Environment
Angular Version:
Angular: 12
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to Validate Angular Template-Driven Forms
If the value entered by the user is already present, ... Run the command shown below to create the template-driven-form component:
Read more >Building a template-driven form - Angular
This tutorial shows you how to create a template-driven form. The control elements in the form are bound to data properties that have...
Read more >Angular template driven form not performing min validation
Here form is not performing min validation check, even if I enter 15 which is less than 18, I see no errors and...
Read more >Template driven form validation in Angular - TekTutorialsHub
In this tutorial, we will look at how validations are handled in Template-driven forms in Angular and learn how to use the Angular...
Read more >Template-Driven Forms • Angular - codecraft.tv
if the property on the left of ? is not null.” So if form.controls.email was null or undefined it would not try to...
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 FreeTop 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
Top GitHub Comments
The browser input needs you let type invalid stuff because, for example, to be able to type the valid number -1, you need to first type
-
, which is not a valid number). The Angular form control works at a higher level: since it’s bound to an input of type number, it knows that what you want is a number, not a string. So every string that isn’t a valid number is turned into a null value. The DOM API is quite close to what Angular does, BTW: the HtmlInputElement’s value, when you type-
or1-
is not the string'-'
of.'1-'
: it’s the empty string.This looks correct to me.
1-
is not a number and you have an input of type number. So the value of the control is not a number: it’snull
. So it’s neither greater nor lower than 5: there is no value at all. If you want such an absence of value to make the control invalid, then therequired
validator should be added to the control.