Opened 14 years ago

Closed 6 years ago

#4547 closed enhancement (patchwelcome)

Form.js - setValue with component expecting an array does not work

Reported by: guest Owned by: bill
Priority: low Milestone: 1.13
Component: Dijit Version: 0.9
Keywords: Cc: [email protected]
Blocked By: Blocking:

Description (last modified by bill)

When Calling setValue with a component expecting an array the form logic does not work.

In my example I'am passing in an Object with a parameters of Roles

Object o = new Object(); 
o.roles = new Array(2);
o.roles[0] = 'Admin';
o.roles[1] = 'User';

<input name="roles" dojoType="wcg.picus.user.UserRolePane">

The component will be passed a single object with the String admin instead of the Roles Array.

The problem is caused by the form-code treating Arrays Differently to other Objects. I tracked the bug down to the following code:

values = [ values ];

on Replacing this with

values = [ values ];

The bug is fixed.

I'am marking this as a critical, as the form logic is useless for our project without the fix.

Attachments (1)

test_form.html (1.4 KB) - added by guest 14 years ago.
Form test for Array Support

Download all attachments as: .zip

Change History (15)

comment:1 Changed 14 years ago by bill

Milestone: 1.01.1

Hmm, first off you should declare variables using the "var" keyword not an object keyword, and also the way you define a new Object and Array is strange. Probably something like:

var o = { roles: ['Admin', 'User'] };

is what you want. I doubt that's the cause of your problem, but anyway try fixing that and then attach a testcase to this bug *using the "Attach File" button*.

Changed 14 years ago by guest

Attachment: test_form.html added

Form test for Array Support

comment:2 Changed 14 years ago by guest

Hi Bill, Thanks for the quick update, I look forward to seeing your team at the Dojo Training course in London.

  1. I know, I was just mocking up an example quickly that would highlight the problem.

I have attached a test-case (for firefox), commenting out the Array Check in the Form setValue method resolved the problem for me.

As it's a simple solution, would it be possible to schedule for 1.0 otherwise I have to patch our local dojo again on the 1.0 release.

Hope I have provided enough information

Kind Regards

Keith Long

comment:3 Changed 14 years ago by bill

Thanks for the test case. If you have

var value = {roles:["Admin", "User"], name:"text"};

Then the form should have two or more fields marked name="roles", and the first should be filled in with "Admin" and the second with "User". If there's only one field then it should be filled in with "Admin". That's the intended behavior of the Form widget. I'm not sure that's working yet, but it seems like the problem in your case is that you are expecting a different type of behavior?

comment:4 Changed 14 years ago by guest

Hi Bill, In my case I have a component which is expecting an "Array of values". I need the ability to add and remove roles from a user. A user can have one or more roles. My component has a complete list of the available user roles.

For instance I would set var value = {roles:["Admin", "User"], name:"text"}; form.setValues(value);

use my roles component to remove the "admin" role var result = form.getValues(); console.log(result);

I would expect this would give me: {roles:Admin?, name:"text"};

From my experience of GUI frameworks, I would have expected that fields would be unique. The reason being at the time of designing the form layout, I would not know how many items will appear on the screen as it's in the data for instance I may be an Admin or a User or Both or even something else. i.e. Having a component that expects a list could easily add and remove dijits as neccesary.

The current design would not allow me to maintain the set of roles unless I changed the roles Array into a Dojo ArrayList? etc, but that would mean manipulating the data prior to posting it into the form.

I hope that explains my issue.

Kind Regards

Keith Long

comment:5 Changed 14 years ago by bill

Description: modified (diff)

Thanks for the explanation... hmm, we are kind of between a rock and a hard place here. In your case, presumably just using Form.getValues() and Form.setValues(), I guess it's possible to have uniquely named components that each take an array of values, but if you have a form that you actually submit to the server via standard protocols, every field just has a scalar value, and you need to have multiple fields with the same name. Checkboxes are the most common example of this (see the "Checkboxes" example in but it can apply to plain inputs too.

It sounds like what you need is the Repeater widget which hasn't been ported yet (but it's in version 0.4).

Anyway, I can't just make the change you suggested above because it'll break other things (like Checkboxes).

comment:6 Changed 14 years ago by bill

Milestone: 1.12.0

comment:7 Changed 14 years ago by bill

Priority: highnormal
severity: criticalnormal
Type: defectenhancement

comment:8 Changed 14 years ago by alex

Milestone: 2.01.3

Milestone 2.0 deleted

comment:9 Changed 13 years ago by bill

Description: modified (diff)
Milestone: 1.32.0

comment:10 Changed 9 years ago by bill

Priority: highlow

comment:11 Changed 9 years ago by bill

Milestone: 2.01.10

Might as well check this into SVN and then merge to github, so it's available for the 1.x and 2.x streams.

comment:12 Changed 8 years ago by cjolif

bill if you plan to check that in into 1.10 you should assign yourself to the ticket? If not I guess it is better to remove the 1.10 milestone?

comment:13 Changed 8 years ago by bill

Milestone: 1.102.0
Owner: set to bill
Status: newassigned

comment:14 Changed 6 years ago by dylan

Milestone: 2.01.12
Resolution: patchwelcome
Status: assignedclosed

Given that no one has shown interest in creating a patch in the past 8 years, I'm closing this as patchwelcome.

Note: See TracTickets for help on using tickets.