Closed
Bug 1067623
Opened 10 years ago
Closed 9 years ago
Input type number reports incorrect value if entering an integer with a trailing decimal
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 1005603
People
(Reporter: jeffrey.royer, Unassigned)
Details
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Steps to reproduce:
Using javascript to listen on the "keyup" event on a input type number field. If I use console.log to print out the value in my event handler, entering in "1." reports that the value for the field is "1".
Link to example with code:
http://plnkr.co/edit/8p9MsF
Enter in a "1" (without quotes) into the number Integer field. Console.log reports "1".
Enter in a "1." (without quotes) into the number Integer field. Console.log reports "1".
Actual results:
The input type number field is showing a value of "1" whenever you enter in "1."
Expected results:
The input type number field is should show a value of "1." whenever you enter in "1."
![]() |
||
Comment 1•10 years ago
|
||
Loic, this is NOT a JS engine issue. There's no JS involved, really!
Jonathan, what's the right behavior here? It's not clear to me when exactly number inputs should be coercing their value to what per spec...
Component: JavaScript Engine → DOM: Core & HTML
Flags: needinfo?(jwatt)
![]() |
||
Comment 2•10 years ago
|
||
Well, the spec here:
https://html.spec.whatwg.org/multipage/forms.html#dom-input-value-value
says that setting the 'value' IDL attribute should "invoke the value sanitization algorithm". (I know the user setting the value isn't the same thing, but it affects the IDL attribute and therefore the sanitization algorithm should presumably be run in this case too.)
Then:
https://html.spec.whatwg.org/multipage/forms.html#number-state-%28type=number%29
says "The value sanitization algorithm is as follows: If the value of the element is not a valid floating-point number, then set it to the empty string instead."
Then:
https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floating-point-number
says that "1." is not a valid floating point number, so presumably we should be setting the value to the empty string rather than to "1."...
That said, Chrome sets the 'value' IDL attribute to "1.". Maybe the spec should change. But this is pretty low priority.
Flags: needinfo?(jwatt)
![]() |
||
Updated•9 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•