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.

Negative sign not a valid value for input type number FormControl

See original GitHub issue

Bug Report

Affected Package

The issue is caused by package @angular/forms

Is this a regression?

No

Description

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

github_iconTop GitHub Comments

3reactions
crisbetocommented, Jun 26, 2021

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.

0reactions
angular-automatic-lock-bot[bot]commented, Jul 29, 2021

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

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 >

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