Forked from http://github.com/jakubpawlowicz/jquery.deserialize
This is a very simple jQuery plugin providing 'deserialize' functionality to a form elements. In contrary to some other plugins available it doesn't reinvent the wheel (by utilizing native browser methods) and actually works.
$("#form-id").deserialize(string, options)
Allows you to override the default setting where it is assumed that the blank is serailized as + instead of %20.
// "one+two" would be deserialized as "one two" (this is default)
$("#form-id").deserialize(string, {
blankToPlus : true;
})
// one+two would be deserialized as one+two
$("#form-id").deserialize(string, {
blankToPlus : false;
})
Allows you to limit set of form fields by either black-listing (except) or white-listing (only):
$("#form-id").deserialize(string, {
except : ['generated_token', 'another_field']
})
These options are exclusive: You cannot pass both in the same time.
Allows you to pass function, called when certain fields are being populated:
$("#form-id").deserialize(string,
callback_on : ['one', 'two', 'three'],
callback : function(name, value){
# NOTE: works only in Firefox with Firebug installed
console.log(name + " has been populated by " + value)
}
})
You can leave callback_on
black to call given function on every populated field.
Allows you to change default attribute (name
), which will be used to match fields in this way: [name='value']
.
See demo.html
for some examples.
- allow to pass JSON objects as data for deserialization
except
,only
andcallback_on
options should accept regular expressions- add more examples to reflect all possible options
- add possibility to chage the way the fields are matched