-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Impossible to set the initial value of a input[number]
field to the proper amount of decimals
#16080
Comments
Hi @adamreisnz, am I correct to say you're describing two problems at once here ?
For the latter issue, I think this is default behavior of an input[type=number]: https://plnkr.co/edit/kF6VPK6CsEypedDh8EDG?p=preview So not sure whether or not angularjs is supposed to be changing this behavior ... |
Hi @frederikprijck , not really. I don't mind that the Basically, the way I see it is that there's two ways to possibly fix this problem:
Happy to discuss further to see what options there are. The main thing that bothers me is that natively, |
Did you see my plunkr and how we are not being able to do this outside of AngularJS neither? ( Not saying the current behavior is something I like, I'm just trying to see how AngularJS handles it differently (or not?) compared to native JavaScript. Edit: I'm not sure if there's other, decent, ways to allow this besides from allowing strings for Another possibility is to create a formatter for it, which doesn't require changes to the core. |
The only way is to set it as a string (I have updated the Plunkr https://plnkr.co/edit/8XhP9xLhgNgx6RdAz9ZJ?p=preview). In this case the String So you can in fact, do it outside of Angular, by accepting |
PS: I know that there are probably work arounds imaginable with custom formatters/validators etc. but I feel like this is in fact a bug/omission in Angular and that |
Let's move the discussion in #11464, because it is essentially the same issue, it has more context and there is little value in having parallel discussions on the same subject. |
OK |
I'm submitting a ...
Current behavior:
It is impossible to set the initial value of a
input[number]
field to the proper amount of decimals, for example when one wants to encourage a currency input.Expected / new behavior:
If a model value is
Number(12.5)
, there should be a way to format this to12.50
and have this be displayed in theinput[number]
field, or theinput[number]
field should accept strings that are valid numbers and display them as their string value (e.g.'12.50'
).Minimal reproduction of the problem with instructions:
http://plnkr.co/edit/OROvhJ7A5nZfGT7HQLqJ?p=preview
If you change
$scope.someNumber
to12.5
it works, but there is no way to have the input field pre-populate with12.50
.Manual entry of
12.50
is possible though.Angular version: 1.6.4
Browser: all
Anything else:
A user can manually input 12.50 in the
input[number]
field without problems (as it is in fact a valid number), so I think we should be able to put that kind of value into the input field through the model as well.Currently, this is not possible, because if you run the value through the number filter first for example, it converts into a string and then Angular throws the
ngModel:numfmt
error.Ideally,
input[number]
should in fact accept strings in the model and display them as they are, provided that they are a valid number.Possibly related:
#11157
#11464
The text was updated successfully, but these errors were encountered: