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 is really slow.

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.

see http://dev.rubyonrails.org/ticket/10453

Benoit



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);
  }



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to