Negative sign not a valid value for input type number FormControl
See original GitHub issueBug Report
Affected Package
The issue is caused by package @angular/forms
Is this a regression?
NoDescription
Negative sign `-` is not allowed to be set using FormControl `patchValue` method on input type `number`.It is a valid value as per https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number and using something like the following should work:
this.inputFormControl.patchValue('-');
Minimal Reproduction
Angular v11.0.8: https://stackblitz.com/edit/angular-btkzby?file=src/app/app.component.ts Angular v12.1.0: https://stackblitz.com/edit/angular-ivy-orrz1w?file=src/app/app.component.ts
Button ‘Set negative sign’ does not work Button ‘Set negative value’ works
Your Environment
Angular Version:
11.0.8
12.1.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
html - Is there any way to prevent input type="number" getting ...
I wanted to allow decimal numbers and not clear the entire input if a negative was inputted. This works well in chrome at...
Read more >Trouble setting negative value for input field - Archive
I'm trying to set a negative value on an input field that always defaults to 0. When using setText to enter 7500, it...
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 >input type=number'' min max not working angular 8
I prefer this method of preventing bad values rather than alerting the user that they have entered a bad value. You signed in...
Read more >HTML Standard
2.3.4.1 Signed integers; 2.3.4.2 Non-negative integers; 2.3.4.3 Floating-point numbers ... 4.10.17.1 A form control's value; 4.10.17.2 Mutability ...
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
I think that this is a browser limitation, because all the Forms module does is set
someInput.value = '-';
which isn’t a valid number. The browser allows you to type it in manually, because otherwise there would be no way of typing in negative numbers.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.