Created
April 6, 2009 20:23
-
-
Save nickstenning/90917 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Element.implement({ | |
| toObject: function () { | |
| var obj = {}; | |
| this.getElements('input, select, textarea, button').each(function(el){ | |
| if (!el.name || el.disabled) return; | |
| var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){ | |
| return opt.value; | |
| }) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value; | |
| $splat(value).each(function(val){ | |
| if (typeof val !== "undefined") { obj[el.name] = val; } | |
| }); | |
| }); | |
| return obj; | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment