mootools/mootools-core — Issue #2239: Improvement to toQueryString
Author: ibolmo
Created: 2012-01-19 10:08:16+00:00
State: open
Labels: enhancement

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