Created
March 31, 2020 13:01
-
-
Save daniel12fsp/5409ae13fd30e2467f598804e2767e19 to your computer and use it in GitHub Desktop.
serializer_form_to_json
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
// Function rule copied from https://api.jquery.com/serializeArray implementation | |
form = document.querySelector("form") | |
rselectTextarea = /^(?:select|textarea)/i; | |
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i | |
Array.from(form.elements).filter(function(elem){ | |
return elem.name && !elem.disabled && | |
( elem.checked || rselectTextarea.test( elem.nodeName ) || | |
rinput.test( elem.type ) ); | |
}).reduce((obj, currentValue) => ({...obj, [currentValue.name]:obj[currentValue.name]? [obj[currentValue.name], currentValue.value]: currentValue.value })) | |
//Reset form.reset() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment