PDA

View Full Version : [OPEN-1438] Ext.urlEncode() - arrays



vojta.jina
11 Nov 2010, 10:20 AM
Ext.urlEncode({arr: [1,2]})

should return:
arr[]=1&arr[]=2

instead of:
arr=1&arr=2

Btw. why ExtJs does not use Github ? It would be so easy, to fix that issue, so you could merge it, if you like it...

tryanDLS
11 Nov 2010, 12:28 PM
I don't think so. Here's one of many threads regarding this http://www.sencha.com/forum/showthread.php?14520-2.0a1-CLOSED-Ext.urlEncode-array-bug&p=70517#post70517.

Barzoy
11 Nov 2010, 11:32 PM
A bit of magic to make Ext more friendly to PHP users



Ext.apply(Ext, {
urlEncode: function(o, pre) {
var empty,
array,
buf = [],
e = encodeURIComponent;

Ext.iterate(o, function(key, item){
empty = Ext.isEmpty(item);
array = Ext.isArray(item);
Ext.each(empty ? key : item, function(val){
buf.push('&', e(array ? key + '[]' : key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
});
});
if(!pre){
buf.shift();
pre = '';
}
return pre + buf.join('');
}
});


Execute it once just after Ext initialized to replace original Ext.urlEncode function with fixed one.

vojta.jina
17 Nov 2010, 12:33 AM
@Barzoy: thanks a lot for useful code, I did almost the same :-D

@tryanDLS: Sorry for creating new post, I did not find this old post...
I understand it's a PHP specific...