Opened 13 years ago
Closed 5 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 )
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:
if(!dojo.isArray(values)){ values = [ values ]; }
on Replacing this with
//if(!dojo.isArray(values)){ 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)
Change History (15)
comment:1 Changed 13 years ago by
Milestone: | 1.0 → 1.1 |
---|
comment:2 Changed 13 years ago by
Hi Bill, Thanks for the quick update, I look forward to seeing your team at the Dojo Training course in London.
- 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 13 years ago by
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 13 years ago by
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 13 years ago by
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 http://www.w3schools.com/html/html_forms.asp) 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 13 years ago by
Milestone: | 1.1 → 2.0 |
---|
comment:7 Changed 13 years ago by
Priority: | high → normal |
---|---|
severity: | critical → normal |
Type: | defect → enhancement |
comment:9 Changed 12 years ago by
Description: | modified (diff) |
---|---|
Milestone: | 1.3 → 2.0 |
comment:10 Changed 8 years ago by
Priority: | high → low |
---|
comment:11 Changed 8 years ago by
Milestone: | 2.0 → 1.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 7 years ago by
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 7 years ago by
Milestone: | 1.10 → 2.0 |
---|---|
Owner: | set to bill |
Status: | new → assigned |
comment:14 Changed 5 years ago by
Milestone: | 2.0 → 1.12 |
---|---|
Resolution: | → patchwelcome |
Status: | assigned → closed |
Given that no one has shown interest in creating a patch in the past 8 years, I'm closing this as patchwelcome.
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:
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*.