Download
User Rating: 3.9/5 ( 1 votes)
jquery-keepFormData is a jQuery plugin that allows you to restore the values of the form's fields, the state of checkboxes, radio buttons and select elements that the user entered, after reloading the page. By default, values are stored until form's submit.
jquery-keepFormData keeps values in localStorage. According to caniuse.com localStorage is supported by Internet Explorer 8.0+, Firefox 26.0+, Chrome 31.0+, Safari 7.0+, Opera 19.0+.
Source: aishek.github.io
1. INCLUDE JS FILES
<script src="http://code.jquery.com/jquery-1.7.0.min.js"></script>
<script src="/js/jquery.keepFormData.js"></script>
2. HTML
To work correclty, the plugin needs:
-
value of the form's id attribute, unique for all site's forms;
-
value of the control's name attribute, which state you want to save, unique for all form's controls.
jquery-keepFormData automatically applied for form elements with keepFormData class:
<form id="name_form" class="keepFormData">
<input name="name">
<input type="submit">
</form>
3. API
By default, control's states and values are resetted. You may change this behaviour, by setting form's data-keep-form-data-clear-on-submit to any of 0, no, false, off.
<form id="name_form" class="keepFormData" data-keep-form-data-clear-on-submit="no">
<input name="name">
<input type="submit">
</form>
For any form there is the $.keepFormData.Form class instance –$('#name_form').data('keepFormDataInstance').
You may call it's method to reset all controls states and values: $.keepFormData.Input – $('#name_form input[name=name]').data('keepFormDataInstance').
For any control there is the $.keepFormData.Input class instance – $('#name_form input[name=name]').data('keepFormDataInstance'). This class instance have public methods:
-
$('#name_form input[name=name]').data('keepFormDataInstance').clear_value() – reset control;
-
$('#name_form input[name=name]').data('keepFormDataInstance').save_value() – save control's state;
-
$('#name_form input[name=name]').data('keepFormDataInstance').load_value() – restore control's state.