Documenation

SerializeObject is used to return data, there are no configurable options as such. However the returned data will be formatted depending on the types of form fields from which data is retrieved.

Usage

var data = $('form').serializeObject();

Return Value(s)

The function will return an object, keys are determined by the value of an input’s name attribute. The type of returned value will be determined by either the attributes name or type of input.

  • Input submitted with no value will return NULL.
  • Unique input name’s will return a string.
  • Input that store more than one value(checkboxes and multiselects), will store the values as an object. Unless one selection is made where the value will be returned as a string.
  • Input name’s appended with square brackets(‘[]’) will return an array of values.
  • Input name’s appended with square brackets and a given property name(‘[property_name]’) will return an object of key/value pairs.

Notes/Issues

  • The ‘name’ attribute is the only requirement for a key/value pair to be set on the object. If this is omitted from the input, the property will not be set in the returned object.
  • As always with client side validation, this does not replace the need for validation on the server side.
  • I have tried to incorporate as many common form inputs and techniques I can think of, if you think I have missed any let me know.