Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#1407 closed defect (fixed)

connect onclick event to checkbox widget fails

Reported by: jan831@… 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)

test_Checkbox_onclick.html (2.4 KB) - added by jan831@… 13 years ago.
checkbox.patch (830 bytes) - added by guest 13 years ago.
test_Checkbox_onclick.2.html (2.8 KB) - added by guest 13 years ago.

Download all attachments as: .zip

Change History (10)

Changed 13 years ago by jan831@…

Attachment: test_Checkbox_onclick.html added

Changed 13 years ago by guest

Attachment: checkbox.patch added

Changed 13 years ago by guest

comment:1 Changed 13 years ago by doughays@…

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.

comment:2 Changed 13 years ago by Adam Peller

Owner: changed from bill to Adam Peller

comment:3 Changed 13 years ago by bill

onClick does work; just see the latest test_Checkbox.html. But you shouldn't be calling getElementsByName() or getElementsById().

comment:4 Changed 13 years ago by bill

Resolution: fixed
Status: newclosed

(In [5563]) Fixes #1407 (although it's debatable whether the user should be able to handle onClick like specified in the bug report) Patch from Doug (IBM, CCLA on file).

comment:5 Changed 13 years ago by trac.dojotoolkit.org@…

Resolution: fixed
Status: closedreopened

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 13 years ago by bill

Resolution: fixed
Status: reopenedclosed

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.

comment:7 Changed 12 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.