Opened 10 years ago

Closed 10 years ago

#9420 closed defect (fixed)

dojo.formToObject radio button: value is array or string depending on the selection

Reported by: Juho Manninen Owned by: anonymous
Priority: high Milestone: 1.4
Component: General Version: 1.3.1
Keywords: Cc:
Blocked By: Blocking:

Description

dojo.formToObject returns an object where value for a radio button group can be either an array or a string. This depends on whether the last or any other button is checked.

If we have a group of 4 radio buttons and we select the last one, we get "4". Selecting the second last leads to ["4",null] and selecting the first to ["4",null,null,null]. See file attached demonstrating this.

From my point of view this should always return string.

Affects at least versions from 1.2 to 1.3.1. Not connected to dojo.fieldToObject.

Attachments (3)

test_dojoFormToObject.html (1.7 KB) - added by Juho Manninen 10 years ago.
Simple form with radio buttons demonstrates the bug
formToObject.diff (534 bytes) - added by Juho Manninen 10 years ago.
Proposed fix filters out null values [CLA]
formToObjectRadioGroupTests.diff (1.3 KB) - added by Juho Manninen 10 years ago.
Extended xhr tests to verify the patch

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by Juho Manninen

Attachment: test_dojoFormToObject.html added

Simple form with radio buttons demonstrates the bug

Changed 10 years ago by Juho Manninen

Attachment: formToObject.diff added

Proposed fix filters out null values [CLA]

comment:1 Changed 10 years ago by Juho Manninen

The attached diff fixes the problem for radio button and checkbox groups. It doesn't break the current checkbox behavior: If a checkbox group has several selected it results to an array. Textboxes are not affected as the value is an empty string, not a null value.

CLA Manninen.

Changed 10 years ago by Juho Manninen

Extended xhr tests to verify the patch

comment:2 Changed 10 years ago by Juho Manninen

Actually, (now that I got my versions correct) unlike I reported earlier, this bug is caused exactly by dojo.fieldToObject (#8649) patch in [17469]. Consequently doesn't affect 1.2 or 1.3.

comment:3 Changed 10 years ago by bill

IIUC, I dealt with the same issue in dijit.form.Form.

You might want to also check (no pun intended) that checkboxes (multiple checkboxes w/the same name) work correctly. Do they always return an array, even when exactly one checkbox is checked?

comment:4 Changed 10 years ago by James Burke

Resolution: fixed
Status: newclosed

(In [18030]) Fixes #9420, #8649, treat single value radio or checkboxes as just a string. Thanks to Maine (CLA) for testcases and the fix.

Note: See TracTickets for help on using tickets.