JSFiddle - React, Tailwind, and code Playground
by ariehg
HTML
<form id='bla'>
<input name='a[a]'/>
<input name='a[b]'/>
</form>
<a href='#' id='click'>click</a>
JavaScript
Element.implement({
serialize : function serialize(){
var results = {};
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){
return $(opt).get('value');
}) : ((type == 'radio' || type == 'checkbox') && !el.checked) ? null : el.get('value');
if (value) results[encodeURIComponent(el.name)] = encodeURIComponent(value);
});
return results;
}
});
$('click').addEvent('click',function(){console.log($('bla').serialize())})