Opened 13 years ago

Closed 12 years ago

#2248 closed defect (fixed)

[patch][cla] IE: dojo.byId() workaround fails to lookup form element if it contains a hidden field

Reported by: Thorsten Berger <dojo@…> Owned by: James Burke
Priority: high Milestone: 0.9
Component: General Version: 0.4.1
Keywords: dojo.byId, null, Internet Explorer, workaround Cc: bill, Douglas Hays
Blocked By: Blocking:

Description

We faced a really strange problem in Internet Explorer 6/7 when posting forms with FormBind? that contain hidden fields. The error message was "FormBind?: Couldn't apply, invalid form". Mozilla/Firefox? is not being affected by this.

I tracked down the cause, and dojo.byId() fails to lookup the form element when it contains a hidden field (returns null). This seems to be related to the workaround code for IE, as a raw document.getElementById() works fine in this case.

I'll attach a testcase where dojo.byId returns null. Remove the hidden field and dojo.byId() returns an object.

Regards, Thorsten

Attachments (3)

testCase_Form_HiddenFields.htm (473 bytes) - added by Thorsten Berger <dojo@…> 13 years ago.
testcase
hostenv_browser.diff (624 bytes) - added by nicola.rizzo+dojo@… 13 years ago.
[cla] patch for dojo.byId (hostenv_browser.js)
hostenv_browser_byId_changes_sf.patch (887 bytes) - added by guest 13 years ago.
this patch fixes the issue in Opera 9, IE6, IE7.. no regressions confirmed in FF1.5, Safari

Download all attachments as: .zip

Change History (12)

Changed 13 years ago by Thorsten Berger <dojo@…>

testcase

Changed 13 years ago by nicola.rizzo+dojo@…

Attachment: hostenv_browser.diff added

[cla] patch for dojo.byId (hostenv_browser.js)

comment:1 Changed 13 years ago by nicola.rizzo+dojo@…

The problem arise because IE uses name instead of id:
if your input field is
<input type="hidden" name="id" value="somewhat" />

when you write
alert(document.getElementById("myFormId").id)
you obtain an object, not a string. The dojo's workaround returns null because exists an object with name = "id" in your form.
hth,

Nicola

comment:2 Changed 13 years ago by dylan

Milestone: 0.9
Owner: changed from anonymous to dylan
Status: newassigned
Summary: IE: dojo.byId() workaround fails to lookup form element if it contains a hidden field[patch][cla] IE: dojo.byId() workaround fails to lookup form element if it contains a hidden field

comment:3 Changed 13 years ago by dylan

Owner: changed from dylan to James Burke
Status: assignednew

comment:4 Changed 13 years ago by nicola.rizzo+dojo@…

I suggest a change in the summary:
from: ...if it contains a hidden field
to: ...if it contains a field with name = "id"
Regards,

Nicola

comment:5 Changed 13 years ago by guest

A workaround for the workaround could be to add a check if 'id' is an input field.

if(ele && (ele.id != id) && doc.all && ele.id.tagName != 'INPUT'){

comment:6 Changed 13 years ago by guest

or better, to be more of a general fix

if(ele && (ele.id != id) && doc.all && typeof ele.id == "string"){

Changed 13 years ago by guest

this patch fixes the issue in Opera 9, IE6, IE7.. no regressions confirmed in FF1.5, Safari

comment:7 Changed 13 years ago by guest

I've added another patch that fixes this issue for me (CLA on file, as Sam Foster @ Vignette). I've a test page that demonstrates the issue at: http://www.sam-i-am.com/work/sandbox/dojo0.4/test_formsById.html

this uses dojo trunk as of today (May-10 2007). The patch fixes the issue in IE6, 7, Opera 9, and confirmed to work on this test page (no regressions) in FF1.5, Safari

comment:8 in reply to:  7 Changed 13 years ago by guest

Replying to guest:

I've added another patch that fixes this issue for me (CLA on file, as Sam Foster @ Vignette). I've a test page that demonstrates the issue at: http://www.sam-i-am.com/work/sandbox/dojo0.4/test_formsById.html

this uses dojo trunk as of today (May-10 2007). The patch fixes the issue in IE6, 7, Opera 9, and confirmed to work on this test page (no regressions) in FF1.5, Safari

ugh, maybe I misunderstood this issue and I'm patching for a seperate problem. I've filed as seperate ticket (#2982), and you can delete/merge as appropriate.

comment:9 Changed 12 years ago by Sam Foster

Cc: bill Douglas Hays added
Resolution: fixed
Status: newclosed

I've attached another test case (byId.html) that demontrates the bug (CLA on file) The form has id="elm1" (arbitrary), it has an input element with name="id". In IE6, the bug was when I dojo.byId("elm1") i *dont* get the form, I get the input instead.

As of today this test now passes in IE6, and passes in FF, IE7. I never really understood the original issue that required the workaround - we should add test cases for that too though. It might be good to add this (byId.html) to the core html tests module to track it. afaict this issue is resolved now the patch is applied so I'm closing it.

Sam

Note: See TracTickets for help on using tickets.