This project is archived and is in readonly mode.

#1261 ✓invalid
Willis Blackburn

Improvement to toQueryString

Reported by Willis Blackburn | August 13th, 2011 @ 02:46 PM | in 2.0 (closed)

I found this function in toQueryString. I'd like to use the anonymous function independently so that I can convert a single input/select/textarea element into a query string. Could toQueryString be changed so that toQueryString on a input/select/textarea executes the logic in the inner anonymous function, while in the form case, it iterates over the child input/select/textarea as it does now, calling the same function for each?

    this.getElements('input, select, textarea').each(function(el){
        var type = el.type;
        if (!el.name || el.disabled || type == 'submit' || type == 'reset' || type == 'file' || type == 'image') return;

        var value = (el.get('tag') == 'select') ? el.getSelected().map(function(opt){
            // IE
            return document.id(opt).get('value');
        }) : ((type == 'radio' || type == 'checkbox') && !el.checked) ? null : el.get('value');

        Array.from(value).each(function(val){
            if (typeof val != 'undefined') queryString.push(encodeURIComponent(el.name) + '=' + encodeURIComponent(val));
        });
    });
    return queryString.join('&');

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages