marioizquierdo / jquery.serializeJSON

Serialize an HTML Form to a JavaScript Object, supporting nested attributes and arrays.
MIT License
1.72k stars 431 forks source link

Reimplement jQuery's serializeArray with extended funcionality #115

Closed marioizquierdo closed 3 years ago

marioizquierdo commented 3 years ago

Instead of relying on jQuery's serializeArray method, the plugin now re-implements its own method with the exact same functionality, but extending its behavior to include the DOM element in the returned list of objects. This allows the plugin to handle multiple inputs with the same name, which is common when defining arrays. Fixes #67.

Functions provided as custom types (customTypes option) now receive an optional second argument with the DOM element. This allows for more powerful integrations between serializeJSON and other plugins. This implements the proposal on issue #109.

In addition, the extended serializeArray handles unchecked checkboxes with the plugin options, which simplifies the code and allows using unchecked checkboxes for array elements (with the same input name, e.g. "myarray[]").