Created
December 15, 2015 17:33
-
-
Save mafigit/770cd4927a1dbc40b87a to your computer and use it in GitHub Desktop.
serializeAllArray (same as serializeArray but with disabled fields included). can be used to completly restore a empty form
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
(function ($) { | |
$.fn.serializeAllArray = function () { | |
var serialize_array = | |
$('input',this).toArray().reduce(function(acc, input) { | |
var form_attr = input.name; | |
var form_value = $(input).val(); | |
if ($(input).is(":checkbox") && !$(input).is(":checked")) { | |
form_value = 0; | |
} | |
if($(input).is(":radio")) { | |
form_value = $("input[name='" + form_attr + "']:checked").val(); | |
} | |
if (form_attr) { | |
acc.push({ | |
name: form_attr, | |
value: form_value | |
}); | |
} | |
return acc; | |
},[]); | |
return serialize_array; | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment