Implement valueAsNumber for <input type='number'>

RESOLVED FIXED in mozilla16

Status

()

Core
DOM: Core & HTML
RESOLVED FIXED
6 years ago
4 years ago

People

(Reporter: mounir, Assigned: mounir)

Tracking

(Blocks: 1 bug, {doc-bug-filed, html5})

Trunk
mozilla16
doc-bug-filed, html5
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

6 years ago
Actually, we don't want that. Olli and I tried to have it removed from the specs but I wrote a patch a long time ago so I'm going to refresh it and attach it here.
Bug against the specs: http://www.w3.org/Bugs/Public/show_bug.cgi?id=11887
(Assignee)

Updated

6 years ago
(Assignee)

Comment 1

6 years ago
Created attachment 515087 [details] [diff] [review]
Patch v1

I'm asking a review but this might be canceled and the bug marked as WONTFIX if the specs remove this attribute.
Assignee: nobody → mounir.lamouri
Status: NEW → ASSIGNED
Attachment #515087 - Flags: review?(jonas)
(Assignee)

Updated

6 years ago
Whiteboard: [needs review]
(Assignee)

Comment 2

6 years ago
Created attachment 515641 [details] [diff] [review]
Patch v1.1

Use double instead of float.
Attachment #515087 - Attachment is obsolete: true
Attachment #515087 - Flags: review?(jonas)
Attachment #515641 - Flags: review?(jonas)
(Assignee)

Updated

6 years ago
Depends on: 636750

Comment 3

6 years ago
I'd still like to see either a reasoning for valueAsNumber or it to be
removed from HTML.
(Assignee)

Updated

6 years ago
Blocks: 639661
Comment on attachment 515641 [details] [diff] [review]
Patch v1.1

>+nsHTMLInputElement::GetValueAsNumber(double* aValueAsNumber)
>+{
>+  if (!DoesValueAsNumberApply()) {
>+    *aValueAsNumber = std::numeric_limits<double>::quiet_NaN();
>+    return NS_ERROR_DOM_INVALID_STATE_ERR;
>+  }

XPCOM rules actually dictate that you should not assign to the out parameter here.

r=me with that fixed
Attachment #515641 - Flags: review?(jonas) → review+
(Assignee)

Comment 5

6 years ago
(In reply to comment #4)
> Comment on attachment 515641 [details] [diff] [review]
> Patch v1.1
> 
> >+nsHTMLInputElement::GetValueAsNumber(double* aValueAsNumber)
> >+{
> >+  if (!DoesValueAsNumberApply()) {
> >+    *aValueAsNumber = std::numeric_limits<double>::quiet_NaN();
> >+    return NS_ERROR_DOM_INVALID_STATE_ERR;
> >+  }
> 
> XPCOM rules actually dictate that you should not assign to the out parameter
> here.
> 
> r=me with that fixed

Eh, this was actually, wrong: I shouldn't throw an exception when getting a value while valueAsNumber doesn't apply but just returning NaN. This is fixed locally.
Whiteboard: [needs review] → [ready to land][waits for dependencies]
(Assignee)

Updated

6 years ago
Whiteboard: [ready to land][waits for dependencies] → [ready to land][waits for dependencies][wait for specs decision]

Comment 6

6 years ago
Spec bug has been closed as RESOLVED WONTFIX, so I guess patch should be landed into m-c.
(Assignee)

Comment 7

6 years ago
(In reply to Atul Aggarwal from comment #6)
> Spec bug has been closed as RESOLVED WONTFIX, so I guess patch should be
> landed into m-c.

This will land with the entire <input type='number'> patch queue which is not ready yet.
(Assignee)

Comment 8

5 years ago
https://hg.mozilla.org/mozilla-central/rev/340c38628ed5
Status: ASSIGNED → RESOLVED
Last Resolved: 5 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Whiteboard: [ready to land][waits for dependencies][wait for specs decision]
Target Milestone: --- → mozilla16

Comment 9

5 years ago
This patch landed too early, as Firefox 16 has no input type=number, but this numberAsValue! Without number support, the result is always NaN, which breaks feature detection.

if (input.valueAsNumber !== undefined){
... input.valueAsNumber;
}else{
... parseInt(input.value, 10);
}

Comment 10

5 years ago
Just for the record. The feature detection had to be changed to:
if (input.type === "number" && input.valueAsNumber !== undefined)
the problem is imo still valid.
See bug 866457 for documentation.
Keywords: dev-doc-needed → doc-bug-filed
You need to log in before you can comment on or make changes to this bug.