Opened 12 years ago
Closed 12 years ago
#8212 closed defect (fixed)
dojo.io.iframe programmatic usage does not allow multi-valued form fields
Reported by: | Jared Jurkiewicz | Owned by: | Jared Jurkiewicz |
---|---|---|---|
Priority: | high | Milestone: | 1.3 |
Component: | IO | Version: | 1.2.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
dojo.io.iframe programmatic usage does not allow multi-valued form fields
This problem was reported by a co-worker of mine. He was using iframe programmatically and found that by passing content with a property name that had an array of values as its value, it wouldn't properly post them as a multi-valued field. His exact statement was:
We are sending a key args.content.shareWith with a value = ["user1", "user2"]
It makes it to the server with a single value of user1, user2 as opposed to two separate values.
Here is what is sent (seen using fiddler:
Content-Disposition: form-data; name="shareWith"
user1,user2
but we expect:
Content-Disposition: form-data; name="shareWith"
user1
Content-Disposition: form-data; name="shareWith"
user2
The fix for this is a change to one function: dojo.io.iframe._fireNextRequest
And the fix is to just detect array values and iterate through them, creating multiple inputs:
if(fn){
if(content){
if we have things in content, we need to add them to
the form
before submission var pHandler = function(name, value) {
var tn; if(dojo.isIE){
tn = dojo.doc.createElement("<input type='hidden'
name='"+name+"'>");
}else{
tn = dojo.doc.createElement("input"); tn.type = "hidden"; tn.name = name;
} tn.value = value; fn.appendChild(tn); ioArgs._contentToClean.push(name);
}; for(var x in content){
var val = content[x]; if(dojo.isArray(val) && val.length > 1){
var i; for (i = 0; i < val.length; i++) {
pHandler(x,val[i]);
}
}else{
if(!fn[x]){
pHandler(x,val);
}else{
fn[x].value = val;
}
}
}
}
I've attached a patch for this that will apply to trunk.
If you're okay with the fix, I'll commit it in.
Attachments (1)
Change History (5)
Changed 12 years ago by
Attachment: | dojo.io.iframe_20081202.patch added |
---|
comment:1 Changed 12 years ago by
On the patch: I guess if it is an array, then it is not likely that a form field with that name already exists, so no need to do the fn[x] check for the array case. At least that is what the patch supposes. That should be OK: it seems unlikely that you would pass an array for a value for a single field in the form.
This change keeps the general contract set up by dojo.formToObject and dojo.objectToQuery in the treatment of arrays to values. Patch sounds like a good idea. Feel free to commit.
comment:2 Changed 12 years ago by
Milestone: | tbd → 1.3 |
---|---|
Owner: | changed from James Burke to Jared Jurkiewicz |
Will do. Thanks for the review!
comment:3 Changed 12 years ago by
Status: | new → assigned |
---|
comment:4 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Patch for iframe multivalued attribute issue.