Created
March 6, 2018 12:19
-
-
Save AleksejDix/de342e46c7fc5402d49f176d2ecc445a to your computer and use it in GitHub Desktop.
This file contains 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
const serialize = (form) => { | |
if (typeof form != 'object' && form.nodeName != "FORM") return; | |
const idDisqualified = el => (el.name && !el.disabled && el.type != 'file' && el.type != 'reset' && el.type != 'submit' && el.type != 'button'); | |
const isChecked = el => (el.type != 'checkbox' && el.type != 'radio') || el.checked; | |
return Array | |
.from(form.elements) | |
.filter(el => idDisqualified(el)) | |
.filter(el => isChecked(el)) | |
.reduce((result, el) => { | |
result[el.name] = el.value; | |
return result; | |
}, {}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment