New Post has been published on Html Use
New Post has been published on http://www.htmluse.com/serialize-object-converts-html-form-into-javascript-object/
Serialize Object - Converts HTML form into JavaScript object
Serialize Object is a jquery plugin that Converts HTML form into JavaScript object
Adds the method serializeObject to jQuery, to perform complex form serialization into JavaScript objects.
The current implementation relies in jQuery.serializeArray() to grab the form attributes and then create the object using the input name attributes.
This means it will serialize the inputs that are supported by .serializeArray(), that use the standard W3C rules for successful controls to determine which inputs should be included; in particular:
The input cannot be disabled and must contain a name attribute.
No submit button value is serialized since the form is not submitted using a button.
Data from <input type=âfileâ> inputs are not serialized.
<script src=âjquery.min.jsâ></script>
<script src=âjquery.serialize-object.min.jsâ></script>
<form id=âcontactâ>
<input name=âuser[email]â value=â[email protected]â>
<input name=âuser[pets][]â type=âcheckboxâ value=âcatâ checked>
<input name=âuser[pets][]â type=âcheckboxâ value=âdogâ checked>
<input name=âuser[pets][]â type=âcheckboxâ value=âbirdâ>
<input type=âsubmitâ>
</form>
.serializeObject â serializes the selected form into a JavaScript object
$(âform#contactâ).serializeObject();
//=> user: email: â[email protected]â, pets: ["cat", "dog"]
.serializeJSON â serializes the selected form into JSON
$(âform#contactâ).serializeJSON();
//=> ââuserâ:âemailâ:â[email protected]â,âpetsâ:["cat","dog"]â
FormSerializer.patterns â modify the patterns used to match field names
Many of you have requested to allow â in field names or use . to nest keys. You can now configure these to your heartâs content.
$.extend(FormSerializer.patterns, [a-z0-9_]+)\])*$/i,
key:Â Â Â Â Â /[a-z0-9_-]+);
$.extend(FormSerializer.patterns,
validate: /^[a-z][a-z0-9_]*(?:\.[a-z0-9_]+)*(?:\[\])?$/i
);
Validating and Key parsing
validate â only valid input names will be serialized; invalid names will be skipped
key â this pattern parses all âkeysâ from the input name; You will want to use /g as a modifier with this regexp.
push â pushe a value to an array
<input name=âfoo[]â value=âaâ>
<input name=âfoo[]â value=âbâ>
$(âformâ).serializeObject();
//=> foo: [a, b]
fixed â add a value to an array at a specified index
<input name=âfoo[2]â value=âaâ>
<input name=âfoo[4]â value=âbâ>
$(âformâ).serializeObject();
//=> foo: [, , "a", , "b"]
named â adds a value to the specified key
<input name=âfoo[bar]â value=âaâ>
<input name=âfoo[bof]â value=âbâ>
<input name=âhelloâ value=âworldâ>
$(âformâ).serializeObject();
//=> foo: bar: âaâ, bof: âbâ, hello: âworldâ