Closed Bug 578632 Opened 15 years ago Closed 9 years ago

HTMLFormElement.elements.namedItem("elem-name") should return a collection for multiple elements with the same name

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: stanio, Unassigned)

References

()

Details

(Keywords: html5, testcase)

Attachments

(2 files, 1 obsolete file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.24) Gecko/20100228 SeaMonkey/1.1.19 (Spidey; Mnenhy 0.7.6) Build Identifier: Mozilla/5.0 (Windows; Windows NT 5.1; en-US; rv:2.0b2pre) Gecko/20100713 Minefield/4.0b2pre Having multiple elements with the same name in a form: <input type="checkbox" name="stuff" value="1"> <input type="checkbox" name="stuff" value="2"> <input type="checkbox" name="stuff" value="3"> Gecko yields different results for: HTMLFormElement.elements["stuff"] and: HTMLFormElement.elements.namedItem("stuff") The first one returns a collection of all form elements with the given name, while the second returns just a single element. The second one adheres to the current DOM Level 2 HTML spec [1], while the first behaves as what's commonly implemented in browsers - latest versions of Opera/Safari/Chrome/IE return a collection using both forms of access and the HTML 5 draft also specifies [2] it should be like that. [1] http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-76728479 [2] http://dev.w3.org/html5/spec/forms.html#dom-form-elements Reproducible: Always
Keywords: html5
OS: Windows XP → All
Hardware: x86 → All
Version: unspecified → Trunk
Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached file Sample test
Doing this in a reasonable way involves "overriding" the namedItem from HTMLCollection on whatever interface form.elements would return. Do we support doing that sort of thing in xpidl?
We have at least one case of this already. I don't think you can override in a *derived* interface, but if you have two independent interfaces, xpconnect makes sure that whichever one shows up last in classinfo wins any conflicts.
Hmm. We actually do need the derived bit, to make instanceof work right, no? That's a bit unfortunate...
No, I don't think you do. You can add an interface without changing instanceof behavior.
The object needs to be both instanceof HTMLCollection and instanceof HTMLFormControlsCollection. Per the spec, the latter interface inherits from the former...
Are spec interfaces exposed to script? If so, is there any rule that we cannot have a nsIMozillaHTMLFormControlsCollection which is invisible to script, but has the override version of .namedItem?
> Are spec interfaces exposed to script? Yes. > is there any rule that we cannot have a nsIMozillaHTMLFormControlsCollection > which is invisible to script Hmm... No, but I'm not sure we have a way of creating interfaces that aren't visible to script.
I guess we've got to, though. I'll see what I can do here.
Assignee: nobody → Ms2ger
Attached patch WIP (obsolete) — Splinter Review
Still need to test.
Status: NEW → ASSIGNED
I never really got around to fixing this; might take it up later.
Assignee: Ms2ger → nobody
Status: ASSIGNED → NEW
Seems to have been fixed by bug 648801.
Flags: in-testsuite?
nsFormControlList::NamedItem is still just returning one node. Is that just not being called by the new JS bindings? It seems bad to have different behavior here for JS vs C++.....
I thought you'd say that. How about this?
Assignee: nobody → Ms2ger
Attachment #461268 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #588974 - Flags: review?(bzbarsky)
(In reply to Boris Zbarsky (:bz) from comment #13) > nsFormControlList::NamedItem is still just returning one node. Is that just > not being called by the new JS bindings? It seems bad to have different > behavior here for JS vs C++..... Boris, if you think we should fix that on branch we can move the [getter] to getNamedItem and remove the [forward(getNamedItem)] from namedItem. File a bug if you think we should do that, I'll make a patch.
I don't think we should worry about it for branch.
Comment on attachment 588974 [details] [diff] [review] Cleanup nsIDOMHTMLCollection::NamedItem implementations nsFormControlList::NamedItem has an extra flush and set of aReturn that can go away. And you need to rev all the relevant IIDs. r=me with that.
Attachment #588974 - Flags: review?(bzbarsky) → review+
Turns out that mozilla::dom::binding::HTMLCollection_NamedItem calls GetNamedItem, so despite the fact that the code in nsFormControlList::NamedItem, the attached test case passes...
Assignee: Ms2ger → nobody
Status: ASSIGNED → NEW
WFM with recent Geckos.
Yeah, this got fixed a long while ago, as part of various bindings work.
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: