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.

md-input type="number" required does not update control validation state

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

A required but empty md-input field should turn the control invalid.

What is the current behavior?

Has the input been touched once it’s valid prop stays true even if the the input is empty.

What are the steps to reproduce?

Enter a number and remove it again. Here is a plunker.

What is the use-case or motivation for changing an existing behavior?

Validating forms should be working.

Which versions of Angular, Material, OS, browsers are affected?

Tested with: angular: ‘@2.0.0-rc.4’ forms: ‘@0.2.0’ material: ‘@2.0.0-alpha.6’ Chomre 52.0.2743.82

Is there anything else we should know?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tylermasseycommented, Jul 25, 2016

I’ve experienced this as well.

I think the issue is related to the value of a number input being NaN when the field is empty.

As a temporary workaround, I wrote a custom validator to handle this case. Here’s an example:

static requiredNumber(control: AbstractControl): {[key: string]: boolean} {
        return (isNaN(control.value) || (control.value == null)) ?
            {'required': true} :
            null;
    }
0reactions
angular-automatic-lock-bot[bot]commented, Sep 5, 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 type number "only numeric value" validation
The problem is when a user enters something that is not a number ("123e" or "abc") the FormControl's value becomes null , keep...
Read more >
<input type="number"> - HTML: HyperText Markup Language
A number input is considered valid when empty and when a single number is entered, but is otherwise invalid. If the required attribute...
Read more >
Working with Angular 4 Forms: Nesting and Input Validation
Forms in Angular applications can aggregate the state of all inputs that are under that form and provide an overall state like the...
Read more >
Validating Input | Web Accessibility Initiative (WAI) - W3C
HTML5 defines a range of built-in functionality to validate common types of input, such as email addresses and dates. In some situations, such...
Read more >
Validating form input - Angular
Every time the value of a form control changes, Angular runs validation and generates either a list of validation errors that results in...
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