Coder Social home page Coder Social logo

unserialize-to-form's Introduction

jQuery Unserialize (to) Form
----------------------------
Version 1.0.8

Simple jQuery plugin to unserialize data back into forms.

Usage:

  var s = $("form").serialize(); // save form settings.
  $("form").unserializeForm(s);  // restore form settings

The serialized form data could be saved in a session, perhaps in HTML5 sessionStorage.
Note that saving the serialized data to a cookie is troublesome as not all browsers
implement the same cookie string lengths, so sessionStorage or a SQL db is recommended.

Alternate Usage:

  var cb = function(key, value, [element]) { return true; // or false }

  var s = $("form").serialize();
  $("form").unserializeForm(s, {
    'callback'        : cb,
    'override-values' : false
  });

  callback (optional):
    The above callback is given the element name and value, allowing you to build
    dynamic forms via callback. If you return false, unserializeForm will
    try to find and set the DOM element, otherwise, (on true) it assumes you've
    handled that attribute and moves onto the next.
    The callback will be passed the key and value and, if found, the DOM object it
    will use should you return false. If the DOM object is not found, the third parameter
    will be the empty array jQuery returns when it cannot find an element.
  override-values (optional, default is false):
    Controls whether elements already set (e.g. an input tag with a non-zero length value)
    will be touched by the unserializer. Does not apply to radio fields or checkboxes.
    If you have a use case for radio fields or checkboxes, please file an issue at
    https://github.com/cthielen/unserialize-to-form/issues/ . Also note this option
    does not apply to a callback, i.e. a callback would still have the opportunity
    to override a value even if this option is set to false. It is up to you as
    the callback author to enforce the behavior you wish.

Known issues:

  * Input element arrays are not cleared before being unserialized, resulting in
    the unserialized values _and_ whatever was already set to be set.

Special thanks / Contributors:
  Anton
  Thiago Macedo
  genellern
  Edward Anderson
  hoka
  Scott Kirkland
  Joshua Weinstein
  Gary Green

unserialize-to-form's People

Contributors

cthielen avatar nilbus avatar garygreen avatar simmstein avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.