Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#8426 closed defect (fixed)

Form: multiple TextBoxes with the same 'name' attribute are not returned as array

Reported by: coldfire22x Owned by: Douglas Hays
Priority: high Milestone: 1.4
Component: Dijit - Form Version: 1.2.3
Keywords: Cc:
Blocked By: Blocking:

Description

When creating multiple TextBox? widgets with the same "name" attribute within the same dijit.form.Form, form.attr("value") does not return all of those values as an array. See attached.

Attachments (2)

TestCase.txt (1.3 KB) - added by coldfire22x 10 years ago.
8426.patch (3.3 KB) - added by Douglas Hays 10 years ago.
patch file to create an array for duplicate named widgets

Download all attachments as: .zip

Change History (13)

Changed 10 years ago by coldfire22x

Attachment: TestCase.txt added

comment:1 Changed 10 years ago by Adam Peller

don't names within a form have to be unique?

comment:2 Changed 10 years ago by bill

Owner: set to bill
Status: newassigned

Hmm, that's odd, it works for checkboxes, see http://download.dojotoolkit.org/release-1.2.1/dojo-release-1.2.1/dijit/tests/form/Form.html.

Must be a problem either with the name ("value[]" rather than just "value"), or with TextBox rather than CheckBox. I'll take a look.

comment:3 Changed 10 years ago by bill

Milestone: tbd1.4
Summary: Multiple TextBoxes with the same 'name' attribute are not returned as arrayForm: multiple TextBoxes with the same 'name' attribute are not returned as array

OK, I looked over the code of Form.js. Currently only checkboxes with the same name are handled. Dates back to [9766].

The issue doesn't have anything to do w/the special characters in the name.

comment:4 Changed 10 years ago by Douglas Hays

How will _setValueAttr work with a TextBox? value array?

comment:5 Changed 10 years ago by bill

Owner: changed from bill to Douglas Hays
Status: assignednew

Doug, I think you were working on this, right?

_setValueAttr() with an array should assign the list of values sequentially, so that the first array element gets assigned to the first TextBox and so forth.

Actually, there's code for that already, not sure why it isn't working:

// otherwise, values is a list of values to be assigned sequentially to each widget
dojo.forEach(widgets, function(w, i){
        w.attr('value', values[i]);
});                                     

comment:6 Changed 10 years ago by Douglas Hays

Status: newassigned

Changed 10 years ago by Douglas Hays

Attachment: 8426.patch added

patch file to create an array for duplicate named widgets

comment:7 Changed 10 years ago by bill

The patch looks good for Form.getValue()... is setValue() working correctly too? There should be a test for that.

As I said on IM, I think lines 239-242 could be simplified to dojo.setObject(name, [prev, value], obj);.

The other thing this made me think about was how to handle single checkboxes. I'd like to change the current behavior but I think it needs to wait until 2.0, so I filed #9962.

comment:8 Changed 10 years ago by Douglas Hays

Resolution: fixed
Status: assignedclosed

(In [20239]) Fixes #8426. On Form value get, changes multiple form values with the same name attribute into an array. Set already worked with array values. Added test to Form.html.

comment:9 Changed 10 years ago by bill

Resolution: fixed
Status: closedreopened

On chrome 3 I'm getting failures (in the Form.html unit test) that the value is reported as duplicate: ["three"] instead of duplicate: ["first", "second", "third"]. It's working on FF (although I'm seeing another problem with Editor's value being blank, probably a race condition about the iframe initialization).

comment:10 Changed 10 years ago by Douglas Hays

Resolution: fixed
Status: reopenedclosed

(In [20286]) Fixes #8426. Slowed down test setup to give Editor a chance to render, but unrelated to this ticket. No test errors reported on FF 3.5 or Chrome 3.0 on Windows.

comment:11 Changed 8 years ago by bill

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