Opened 15 years ago

Closed 14 years ago

Last modified 11 years ago

#5222 closed defect (fixed)

dijit.Form.CheckBox onChange method problem

Reported by: guest Owned by: Douglas Hays
Priority: high Milestone: 1.1
Component: Dijit - Form Version: 1.0
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)


I found a problem with the onchange method of dijit.Form.CheckBox? and RadioButton?.

When the widgets are created programmatically the onchange method is fired twice. I didn't test it with markup.

Here under find a code that demonstrate the problem. This occurs with FF, IE6 and IE7, under Windows XP sp2.

Dojo version is 0.9.0dev (11363) major=0 minor=9 patch=0 flag=dev revision=11363

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor,">
 	<script type="text/javascript" 
      		djConfig="isDebug: false, parseOnLoad: true, usePlainJson : true, preventBackButtonFix: false"
 	<script type="text/javascript"> 
    function init() {

      checkBox1 = new dijit.form.CheckBox({
                    id : 'id1'
                   ,value : '1'
                   ,onChange : onChangeCheckBox
               }, dojo.byId("myDiv"));
      checkBox2 = new dijit.form.RadioButton({
                    id : 'id2'
                   ,name : "radio" 
                   ,value : '2'
                   ,onChange : onChangeCheckBox2
               }, dojo.byId("myDiv2"));

      checkBox3 = new dijit.form.RadioButton({
                    id : 'id3'
                   ,name : "radio" 
                   ,value : '3'
                   ,onChange : onChangeCheckBox2
               }, dojo.byId("myDiv3"));

      console.log("before setchecked checkbox1")
      console.log("before setchecked checkbox2")
      console.log("before setchecked checkbox3")

    function onChangeCheckBox(a) {
      console.log("onChangeCheckBox", a, this, this.checked);
    function onChangeCheckBox2(a) {
      console.log("onChangeCheckBox2", a, this, this.checked);
    <div id="myDiv"> </div>
    <div id="myDiv2"> </div>
    <div id="myDiv3"> </div>

Best regards

Roger [email protected]

Change History (4)

comment:1 Changed 15 years ago by bill

Component: GeneralDijit
Description: modified (diff)
Milestone: 1.1
Owner: changed from anonymous to Douglas Hays

Hmm, it shouldn't be getting called at all (on instantiation). Doug, can you fix?

comment:2 Changed 15 years ago by Douglas Hays

The problem is that ToggleButton? setChecked calls onChange directly w/o checking for actual change. Everything should be going thru setValue.

comment:3 Changed 14 years ago by Douglas Hays

Resolution: fixed
Status: newclosed

(In [11982]) Fixes #5222 !strict. Split out the special value processing in _FormWidget and subclassed it into _FormValueWidget so that Button and TextBox? could inherit from different classes, allowing value to be treated like a simple string attribute for Buttons/checkboxes and as complex objects for input widgets (dates/times/currency/etc). Deprecated setChecked and setValue for Button widgets (and subclasses) for the new setAttribute method for all simple attributes. Removed onChange(string) that was being called for Buttons/checkboxes when the value attribute was changed. Only onChange(boolean) should be called for checkboxes.

comment:4 Changed 11 years ago by bill

Component: DijitDijit - Form
Note: See TracTickets for help on using tickets.