Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goog.dom.forms.getValueByName and input named item #449

Closed
dg opened this issue Apr 15, 2015 · 1 comment
Closed

goog.dom.forms.getValueByName and input named item #449

dg opened this issue Apr 15, 2015 · 1 comment

Comments

@dg
Copy link

dg commented Apr 15, 2015

goog.dom.forms.getValueByName() will not work for inputs named item (or namedItem), because form.elements.item is native function (see http://jsfiddle.net/y4hL2k80/ and source code)

I am not aware how to fix it, because form.elements.namedItem(name) in MSIE will not return collection (form.elements in MSIE returns HtmlCollection whereas other browsers return HtmlFormControlsCollection and HtmlFormControlsCollection.namedItem('name') returns RadioNodeCollection containing all inputs, whereas HtmlCollection.namedItem('name') returns only the first one).

@joeltine
Copy link
Contributor

Ya, an unfortunate side effect of using form.elements. The easy answer to this is "just don't use inputs named 'item'". Given that the fix is likely ugly, we haven't had anyone complain about this internally, and the work around is trivial, it's probably not worth the effort.

What we can do though is fail fast with a meaningful message (e.g., throw when elements returns a non-HTMLCollection or user passes the reserved names) or at the very least add a comment to the method. Just silently returning null now (which I assume is what it does) seems bad.

Feel free to re-open and/or send a PR with either of these and I'll review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants