#1407 closed defect (fixed)
connect onclick event to checkbox widget fails
Reported by: | Owned by: | Adam Peller | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Widgets | Version: | 0.3 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
It is not possible to connect an onclick event to a checkbox widget. It does work when connecting to a normal HTML checkbox, or using the onclick attribute
Attachments (3)
Change History (10)
Changed 14 years ago by
Attachment: | test_Checkbox_onclick.html added |
---|
Changed 14 years ago by
Attachment: | checkbox.patch added |
---|
Changed 14 years ago by
Attachment: | test_Checkbox_onclick.2.html added |
---|
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
Owner: | changed from bill to Adam Peller |
---|
comment:3 Changed 14 years ago by
onClick does work; just see the latest test_Checkbox.html. But you shouldn't be calling getElementsByName() or getElementsById().
comment:4 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 Changed 14 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
There are still a few issues with this fix. I'm using Dojo 0.4.1 with Firefox 1.5.0.9
Refering to this checkbox declaration:
<input type="checkbox" id="idCheckBoxField" dojoType="Checkbox"></input> <label for="idCheckBoxField">My Label</label>
1) dojo.event.connect(dojo.widget.byId("idCheckBoxField"), "onclick", alertMsg)
will not work, but dojo.event.connect(dojo.byId("idCheckBoxField"), "onclick", alertMsg)
will. Note use of 'dojo.widget.byId' and 'dojo.byId'
2) dojo.event.connect(dojo.byId("idCheckBoxField"), "onClick", alertMsg)
will not work, but dojo.event.connect(dojo.byId("idCheckBoxField"), "onclick", alertMsg)
will. Note use of 'onclick' and 'onClick'. The opposite is true for buttons (and possibly other widgets, but I haven't tried).
3) Clicking the label text, 'My Label', will change the state of the checkbox, but the onclick event is not fired. Using firebug to view the DOM shows that the label is a sibling of the rendered checkbox span. The onclick event is attached to the span, however.
comment:6 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
The method to attach to is called "onClick" not "onclick". Try
dojo.event.connect(dojo.widget.byId("idCheckBoxField"), "onClick", alertMsg)
Please reopen the bug if there's still an issue.
A few issues here: 1) the testcase's html file provided is doing getElementsByName which doesn't work well with dynamic elements. getElementById should be used instead. 2) the connect call within the provided testcase's html file should be executed within an onload handler so that the widget has time to render the new DOM elements. 3) the checkbox template needs to be changed to set the id of the span element so that getElementById works. The name attribute should remain on the input tag for form submission. After applying the checkbox.patch to the latest trunk and making the changes listed in 1) and 2) to the testcase, then the onclick worked for me. I'll go ahead an include my tweaks to the provided testcase.