PDA

View Full Version : Ext.Ajax.serializeForm : bug for select-multiple



medifirst
17 Jan 2011, 3:51 AM
Ext version tested:


Ext 3.3.1



Adapter used:


ext


css used:


only default ext-all.css


Browser versions tested against:


IE
FF



Operating System:


all



Description:
All of values of a "select-multiple" are not interpreted using form.getValues(true)

Test Case:



<select multiple="multiple" type="select-multiple" id="test">
<option value="1"> opt </option>
<option value="2"> opt </option>
<option value="3"> opt </option>
</select>
Steps to reproduce the problem:

The result of form.getValues(true) is:
test=726300000&test=728200000

The result that was expected:

form.getValues(true) should return
test[]=726300000&test[]=728200000

The result that occurs instead:
test=726300000&test=728200000

Screenshot or Video:


Debugging already done:


Possible fix:




Ext.apply(Ext.lib.Ajax,
{
serializeForm : function(form)
{
var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
hasSubmit = false,
encoder = encodeURIComponent,
name,
data = '',
type,
hasValue;
Ext.each(fElements, function(element)
{
name = element.name;
type = element.type;

if (!element.disabled && name)
{
if (/select-(one|multiple)/i.test(type))
{
var str = /select-multiple/i.test(type) ? '[]' : '';

Ext.each(element.options, function(opt)
{
if (opt.selected)
{
hasValue = opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified;
data += String.format("{0}" + str + "={1}&", encoder(name), encoder(hasValue ? opt.value : opt.text));
}
});
}
else if (!(/file|undefined|reset|button/i.test(type)))
{
if (!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit))
{
data += encoder(name) + '=' + encoder(element.value) + '&';
hasSubmit = /submit/i.test(type);
}
}
}
});
return data.substr(0, data.length - 1);
}
}
);

Condor
17 Jan 2011, 5:00 AM
Not true.

It should only return that if you specified:

<select multiple="multiple" type="select-multiple" name="test[]">
<option value="1"> opt </option>
<option value="2"> opt </option>
<option value="3"> opt </option>
</select>

medifirst
17 Jan 2011, 5:18 AM
You're right, thank you ;-)