New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement to toQueryString #2239

Closed
ibolmo opened this Issue Jan 19, 2012 · 0 comments

Comments

Projects
None yet
1 participant
@ibolmo
Copy link
Member

ibolmo commented Jan 19, 2012

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('&');

@ibolmo ibolmo closed this Mar 3, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment