Is there a jQuery plugin out there that can serialize a form, and then later restore/populate the form given the serialized value? I know the form plugin can serialize as a
checkbox or radio isn't set, the value is nullDeactivates checkbox or radio if value is null
$.fn.formData = function(values) {
var form = $(this);
var inputs = $(':input', form).get();
var hasNewValues = typeof values == 'object';
if (hasNewValues) {
$.each(inputs, function() {
var input = $(this);
var value = values[this.name];
if (values.hasOwnProperty(this.name)) {
switch (this.type) {
case 'checkbox':
input.prop('checked', value !== null && value);
break;
case 'radio':
if (value === null) {
input.prop('checked', false);
} else if (input.val() == value) {
input.prop("checked", true);
}
break;
default:
input.val(value);
}
}
});
return form;
} else {
values = {};
$.each(inputs, function() {
var input = $(this);
var value;
switch (this.type) {
case 'checkbox':
case 'radio':
value = input.is(':checked') ? input.val() : null;
break;
default:
value = $(this).val();
}
values[this.name] = value;
});
return values;
}
};