Opened 12 years ago

Closed 12 years ago

#2869 closed task (fixed)

Checkbox, Radio: api to set/get checked state

Reported by: bill Owned by: davidb
Priority: high Milestone: 0.9beta
Component: Widgets Version: 0.9
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by davidb)

See related dijit forum topic.

Most form widgets have setValue()/getValue() methods but for checkbox and radio buttons, the "value" field is more like the name field; what you need is a function to get/set the checked state.

Example code to illustrate problem:

<input type=radio name=seatType value=coach checked>
<input type=radio name=seatType value=business>
<input type=radio name=seatType value=firstClass>

For a given input we want the ability to set whether or not it is "checked", not what the value (coach/business/firstClass) is.

Attachments (3)

checkedapi.diff (2.7 KB) - added by davidb 12 years ago.
a quick first attempt, adding checked state API to FormElement?.js and using it in Checkbox.js
checkedapi2.diff (2.0 KB) - added by davidb 12 years ago.
this solution might be better; just adds api to Checkbox.js (reposting to add this comment)
checkedapifix.diff (1.1 KB) - added by davidb 12 years ago.
this improves the solution (setChecked updates view, removed unecessary aria etc)

Download all attachments as: .zip

Change History (9)

Changed 12 years ago by davidb

Attachment: checkedapi.diff added

a quick first attempt, adding checked state API to FormElement?.js and using it in Checkbox.js

comment:1 Changed 12 years ago by davidb

Description: modified (diff)

comment:2 Changed 12 years ago by davidb

Status: newassigned

Changed 12 years ago by davidb

Attachment: checkedapi2.diff added

this solution might be better; just adds api to Checkbox.js (reposting to add this comment)

comment:3 Changed 12 years ago by bill

Resolution: fixed
Status: assignedclosed

(In [8373]) setChecked()/getChecked() API. Fixes #2869. Patch by David Bolter (CLA on file).

Changed 12 years ago by davidb

Attachment: checkedapifix.diff added

this improves the solution (setChecked updates view, removed unecessary aria etc)

comment:4 Changed 12 years ago by davidb

Resolution: fixed
Status: closedreopened

Hi Bill,

Could you please commit the checkedapifix.diff patch I just added? It makes sure the view is updated when the user calls setChecked; it also removes some ARIA stuff that I accidentally borrowed when pasting code from my FormElement? solution.

I've been adding some tests for checkbox/radio but am not ready to commit the them just yet, and can do that on another ticket.

comment:5 Changed 12 years ago by bill

(In [8378]) Fix problem with previous patch. Refs #2869.

comment:6 Changed 12 years ago by davidb

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.