Opened 13 years ago

Closed 6 years ago

#8619 closed defect (fixed)

CheckBox: get("value") return code is strange

Reported by: frostmourn Owned by:
Priority: high Milestone: 2.0
Component: Dijit - Form Version: 1.2.3
Keywords: Checkbox Cc:
Blocked By: Blocking:


I use dijit.form.CheckBox? getValue method and found it is strange.When the checkbox is checked, getValue method returns "on" , and when it is not checked, it returns false. I think it's not a good design.By the way , when I use this code:

var value = dojo.byId("checkboxID").value;


var value = dojo.byId("checkboxID").checked;

the value is undefined. It's not convenient for users.

Change History (7)

comment:1 Changed 13 years ago by bill

Milestone: tbd2.0
Summary: the checkbox getValue methodCheckBox: getValue() method return code is strange

Yes, the current behavior is the compromise of a long discussion... the issue is that:

  • unlike plain <input>'s, HTML <input type=checkbox> and dijit.form.CheckBox widgets have both a string value attribute (by default == "on"), and a boolean checked attribute (which reflects whether or not the checkbox is checked).
  • but dojo users wanted getValue() to "work uniformly" across the form widgets, meaning that code could query the "value" of all the widgets inside a form w/out having a special branch for a dijit.form.CheckBox
  • all changes made after 1.0 needed to be backwards compatible

I can't think of any way to change this that would make it "better" in most people's eyes, except maybe returning null or "" rather than false. What change did you have in mind?

comment:2 Changed 13 years ago by Douglas Hays

An added design point was the need for widget.attr('value', widget.attr('value')) to work.

comment:3 Changed 11 years ago by bill

Component: DijitDijit - Form
Owner: set to Douglas Hays

comment:4 Changed 9 years ago by bill

Summary: CheckBox: getValue() method return code is strangeCheckBox: get("value") return code is strange

comment:5 Changed 8 years ago by Douglas Hays

Owner: Douglas Hays deleted
Status: newassigned

comment:6 Changed 8 years ago by Douglas Hays

Status: assignedopen

comment:7 Changed 6 years ago by bill

Resolution: fixed
Status: openclosed

Marking this as fixed in 2.0 because doesn't have that goofy code conflating the checked and value attributes.

Note: See TracTickets for help on using tickets.