Opened 11 years ago

Closed 11 years ago

Last modified 7 years ago

#8660 closed defect (fixed)

IE: getElementsByName failing on widgets

Reported by: Douglas Hays Owned by: bill
Priority: high Milestone: 1.4
Component: Dijit Version: 1.3.0b1
Keywords: Cc: sayuri, Joseph Scheuhammer
Blocked By: Blocking:

Description

dijit widgets have a name attribute that gets submitted with forms, but when you try to do a dojo.query OR getElementsByName, then that fails to return any values.

Attachments (2)

8660.html (1.7 KB) - added by Douglas Hays 11 years ago.
8660.patch (13.9 KB) - added by Douglas Hays 11 years ago.
possible fix? Adds ${=name} to dijit templates, _Templated.js expands that to name=${name}, MappedTextBox? inserts hidden INPUT directly into template, remove _setNameAttr method

Download all attachments as: .zip

Change History (16)

Changed 11 years ago by Douglas Hays

Attachment: 8660.html added

comment:1 Changed 11 years ago by Douglas Hays

Cc: sayuri added

On IE8, getElementsByName works but not dojo.query

Changed 11 years ago by Douglas Hays

Attachment: 8660.patch added

possible fix? Adds ${=name} to dijit templates, _Templated.js expands that to name=${name}, MappedTextBox? inserts hidden INPUT directly into template, remove _setNameAttr method

comment:2 Changed 11 years ago by bill

severity: blockernormal

Note that this regression is fallout from #8484, which seemed to be working (form submit works and Form.attr('value') can also grab the form values correctly). Unfortunately there's this hiccup.

comment:3 Changed 11 years ago by Douglas Hays

Cc: Joseph Scheuhammer added

This defect results in broken RadioButton? keyboard navigaton as described in #8671.

comment:4 Changed 11 years ago by bill

Resolution: fixed
Status: newclosed

(In [16716]) Setting the name attribute after the widget DOM is created, even though it's not attached to <body>, causes subtle problems on IE. Specifically, dojo.query() and getElementsByTagName() don't work. (Even though form submission and dojo.attr(node, 'name') still do work.)

Rollback [16468] and [16474], and implement different solution.

Fixes #8660, #8671, refs #8484 !strict.

comment:5 Changed 11 years ago by Nathan Toone

(In [16785]) Refs #8660, #8671, #8484 - make this change for some of the dojox forms as well to read from the ${nameAttrSetting} value !strict

comment:6 Changed 11 years ago by bill

Resolution: fixed
Status: closedreopened

See also #8678 about test case.

Hmm, I'm trying this now and it's still not working for me... but it doesn't seem to work in 1.2 either. Am I missing something?

See test_FilteringSelect.html on IE6, and try these commands in the console:

dojo.query("input[name=state1]")

and

document.getElementsByName("state1")

both return nothing, even though there is an <input name=state1> in the generated DOM.

Alternately, try dojo.query("input[name=income1]") in test_validate.html.

Maybe it's not finding those nodes because they are display:none. dojo.query("input[name=firstname]") in test_validate.html works fine.

comment:7 Changed 11 years ago by bill

Milestone: 1.31.4
Priority: highnormal
Summary: [regression]: IE: getElementsByName failing on widgetsIE: getElementsByName failing on widgets

OK, Doug confirms that display:none nodes aren't found, which means that getElementsByName() or dojo.query() never worked on IE on anything based on MappedTextBox (which are the majority of our widgets), plus probably Slider too.

We'll think about this some but marking this as not critical for 1.3 for now... the regression that getElementsByName() doesn't work on textboxes itself was fixed, FWIW.

comment:8 Changed 11 years ago by Douglas Hays

If we change the type from this.type to "hidden" and get rid of the display:none, then everything seems to work. We should consider this change but also think about any side-effects (probably none if type=text).

comment:9 Changed 11 years ago by bill

Hmm, on IE6 document.getElementsByName("state1") isn't working for me, even when the hidden field is type=text and fully visible. I think it's because of the way we create the hidden field, using dojo.create():

this.valueNode = dojo.create("input", {
	type: 'text',
	name: this.name
}, this.textbox, "after");

which causes name to be set using dojo.attr() after the DOM node is created.

comment:10 Changed 11 years ago by bill

Resolution: fixed
Status: reopenedclosed

(In [17411]) Can't use dojo.create() to create nodes with name attribute, because then on IE6 dojo.query() can't find those nodes.

I also changed the style="display:none" to type="hidden" but either one seems to work OK.

Fixes #8660 again, !strict.

comment:11 Changed 11 years ago by bill

(In [17412]) Test case for #8660, about finding widgets via dojo.query('*[name=...]'). Refs #8660.

comment:12 Changed 11 years ago by bill

(In [17431]) Save a few bytes as per Pete's suggestion, refs #8660 and [17411].

comment:13 Changed 10 years ago by bill

[19512] Don't add empty name attribute to hidden input field. Fixes #9640, refs #8660, !strict.

comment:14 Changed 7 years ago by bill

In [30156]:

Windows 8 Store Apps throw an exception when trying to set an element's name attribute via innerHTML. So avoid doing that on Windows 8 Apps. Instead, do it via the _setNameAttr custom setter. This is how it should be done for all platforms starting in 2.0.

Old code to set name via innerHTML was left in place for supporting the older versions of IE (refs #8660, #8484). Also, this.nameAttrSetting needs to be remain until 2.0 for backwards compatibility, because custom widgets may be referencing it in their templates.

Changes were tested locally on firefox by changing the conditions in _FormWidget.js and MappedTextBox.js from !has("win8app") to has("ie").

Fixes #16452 !strict.

Note: See TracTickets for help on using tickets.