Greetings,
I'm using Rico Live Grid (Rico2.0 Beta 2) and have found that it is
handling multiple query parameters with the same name incorrectly. It
only passes the last pair.
For example, I have a form with multiple checkboxes where each checkbox
input field has the same name and therefore the post contains something
like fieldNameA=1&fieldNameA=2&fieldNameA=3 etc....; however after the
grid makes the request to the server, that request only contains
fieldNameA=3.
I believe this is because of the following code in ricoLiveAjax.js in
the Rico.Buffer.AjaxXMLMethods object:
formQueryHash: function(startPos,fetchSize) {
if (typeof fetchSize!='number') fetchSize=this.totalRows;
var queryHash= {
id: this.liveGrid.tableId,
page_size: fetchSize,
offset: startPos
};
if (!this.foundRowCount) queryHash['get_total']='true';
if (this.options.requestParameters) {
for ( var i=0; i < this.options.requestParameters.length; i++ ) {
var anArg = this.options.requestParameters[i];
if ( anArg.name != undefined && anArg.value != undefined ) {
queryHash[anArg.name]=anArg.value;
} else {
var ePos = anArg.indexOf('=');
var argName = anArg.substring( 0, ePos );
var argValue = anArg.substring( ePos + 1 );
queryHash[argName]=argValue;
}
}
}
...
}
Its using an object to store the query parameters. So as it
iterates over the query parameters array, it overwrites stored values
using the same name.
Am I missing something?
Has anyone else run into this problem?
on 21.12.2007 14:22
on 22.12.2007 16:57
Okay. After some more digging I found out that Hash.toQueryString(...)
which is used downstream to convert the Hash object to query string
parameters in the Ajax.Request object handles cases where the Hash
object property value is an Array.
So I made the following code change:
formQueryHash: function(startPos,fetchSize) {
if (typeof fetchSize!='number') fetchSize=this.totalRows;
var queryHash= {
id: this.liveGrid.tableId,
page_size: fetchSize,
offset: startPos
};
if (!this.foundRowCount) queryHash['get_total']='true';
if (this.options.requestParameters) {
for ( var i=0; i < this.options.requestParameters.length; i++ ) {
var anArg = this.options.requestParameters[i];
if ( anArg.name != undefined && anArg.value != undefined ) {
//queryHash[anArg.name]=anArg.value;
if (queryHash[anArg.name]) {
var val = queryHash[anArg.name];
if (typeof val == 'object' && val.constructor == Array) {
val[val.length] = anArg.value;
} else {
queryHash[anArg.name] = [val, anArg.value];
}
} else {
queryHash[anArg.name]=anArg.value;
}
} else {
var ePos = anArg.indexOf('=');
var argName = anArg.substring( 0, ePos );
var argValue = anArg.substring( ePos + 1 );
//queryHash[argName]=argValue;
if (queryHash[argName]) {
var val = queryHash[argName];
if (typeof val == 'object' && val.constructor == Array) {
val[val.length] = argValue;
} else {
queryHash[argName] = [val, argValue];
}
} else {
queryHash[argName]=argValue;
}
}
}
}
....
This produces the desired results when the
'this.options.requestParameters' contains something like
["a=1","a=2","a=3"]. Then when Ajax.Request calls
Hash.toQueryString(...), you get a=1&a=2&a=3, instead of just a=3.
There may be a more elegant solution but this works for me so I'm going
with it.
I'm surprised no one else has run into a similar issue.
I would still be interested to see how others dealt with this.
on 02.01.2008 23:07
What if options.requestParameters was:
[ {name:'a', value:[1,2,3]} ]
Wouldn't this work without any code changes?
Matt
on 03.01.2008 12:36
Yep.
I knew this nut had been cracked before.
I was using Form.serialize(form) to get parameter changes, then using a
split operation to convert it into an array of name=value pairs.
However, formQueryHash started choking on the duplicate names.
So now, I use Form.serialize(form), then convert that array into an
array of JSON {name:a, value:[x,y,z]} objects and pass that along to
options.requestParameters and it works fine.
So, your right, if you have duplicate names in the query string, you
would have to convert it to an array of JSON objects and it works fine
without an API code change.
Thanks Matt.


