When using Form.serialize on forms containing a lot of elements (input, select, etc..) the serialization speed on IE 6 is awful due to the use of Element.extend.
Even if the elements have no name attribute the serialization speed is really low.
By using a specialised version of serialize which do not use Element.extend i was able to cut the execution time by 70% on big forms.
The improvement is less impressive on ff and safari but exists.
2 files attached to this ticket :
- bigform.html which tests the new method vs the current one
- form.js which contains 2 new method fastSerialize and _fastSerializeElements
Benoit WIART
UBIK Ingénierie
fastSerialize: function(form, options) {
return Form._fastSerializeElements($(form).getElementsByTagName('*'), options);
},
_fastSerializeElements: function(elements, options) {
if (typeof options != 'object') options = { hash: !!options };
else if (Object.isUndefined(options.hash)) options.hash = true;
var key, value, submitted = false, submit = options.submit;
var result = {};
for(var i=0, size=elements.length; i <size; i++)
{
var element = elements[i];
var name = element.name;
if (!name)
continue;
if (Form.Element.Serializers[element.tagName.toLowerCase()])
{
if (!element.disabled) {
key = name, value = Form.Element.Serializers[element.tagName.toLowerCase()](element);
if (value != null && (element.type != 'submit' || (!submitted &&
submit !== false && (!submit || key == submit) && (submitted = true)))) {
if (key in result) {
// a key is already present; construct an array of values
if (!Object.isArray(result[key])) result[key] = [result[key]];
result[key].push(value);
}
else result[key] = value;
}
}
}
}
return options.hash ? result : Object.toQueryString(result);
}