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.

Entering invalid value in template drive form showing valid status

See original GitHub issue

Bug Report

Affected Package

The issue is caused by package @angular/forms

Is 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

Reproduction

https://stackblitz.com/edit/angular-ivy-g1zbbb?file=src/app/app.component.html

Your Environment

Angular Version:

Angular: 12

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jnizetcommented, Jun 27, 2021

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 - or 1- is not the string '-' of. '1-': it’s the empty string.

2reactions
jnizetcommented, Jun 26, 2021

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’s null. 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 the required validator should be added to the control.

Read more comments on GitHub >

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

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