Download Demo
Formcache is a simple jQuery form cache plugin.
Browser Support
2. HTML
3. JAVASCRIPT
4. OPTIONS
key
By default, the form’s index in the document will be used as the key.
local
session
autoStore
maxAge
By default, the session caches will be cleared when the browser closes, and the local caches will be stored all the time.
Notes:
A jQuery selectors array. Defines the form controls which need to be cached.
Note: All file inputs will be ignored always by default.
5. METHODS
getCache([index])
Get the default cache object or a special one.
Examples:
Get all cache objects.
Examples:
Override the default cache object or add a new one.
Examples:
Override the old caches with new caches.
Examples:
Remove the default cache object or a special one.
Examples:
Remove all cache objects.
Examples:
Output the default cache object or a special one to the form.
The outputed cache object will be updated automatically when any form control changed.
Examples:
Serialize the form and return a cache object.
Examples:
Store all caches to sessionStorage or localStorage.
The plugin will do this automatically when a form control changed, or the window unloaded.
clear()
Clear all caches.
destroy()
Destroy the formcache instance, but keep the caches.
If you want to remove all caches, you can call clear method first and then call the destroy method.
- Chrome 31+
- Firefox 31+
- Internet Explorer 8+
- Opera 26+
- Safari 5.1+
- iOS Safari 7.1+
- Android Browser 4.1+
- Chrome for Android 39+
<script src= "/path/to/jquery.js" ></script><!-- jQuery is required --> <script src= "/path/to/formcache.js" ></script> |
<form id= "form" ></form> |
$( '#form' ).formcache(); |
key
- Type: String | Number
- Default: ”
By default, the form’s index in the document will be used as the key.
local
- Type: Boolean
- Default: true
session
- Type: Boolean
- Default: true
autoStore
- Type: Boolean
- Default: true
maxAge
- Type: Number
- Default: undefined
By default, the session caches will be cleared when the browser closes, and the local caches will be stored all the time.
Notes:
- session caches still will be cleared when the browser closes.
- local caches still will be cleared when the browser caches clears.
- Type: Array
- Default:
[ 'select', 'textarea', 'input' ]
Note: All file inputs will be ignored always by default.
5. METHODS
getCache([index])
Params | Type | Default | Description |
---|---|---|---|
index | Number | 0 | Cache index |
Examples:
$().formcache('getCache') $().formcache('getCache', 1)getCaches()
Get all cache objects.
Examples:
$().formcache('getCaches')setCache([index, ]data)
Params | Type | Default | Description |
---|---|---|---|
index | Number | 0 | Cache index |
data | Object | Cache item |
Examples:
$().formcache('setCache', {}) $().formcache('setCache', 1, {})setCaches(data)
Params | Type | Description |
---|---|---|
data | Array | Cache items |
Examples:
$().formcache('setCaches', [{}]) $().formcache('setCaches', [{}, {}])removeCache([index])
Params | Type | Default | Description |
---|---|---|---|
index | Number | 0 | Cache index |
Examples:
$().formcache('removeCache') $().formcache('removeCache', 1)removeCaches()
Remove all cache objects.
Examples:
$().formcache('removeCaches')outputCache([index])
Params | Type | Default | Description |
---|---|---|---|
index | Number | 0 | Cache index |
The outputed cache object will be updated automatically when any form control changed.
Examples:
$().formcache('outputCache') $().formcache('outputCache', 1)serialize()
Serialize the form and return a cache object.
Examples:
var cache = $('form').formcache('serialize'); $('form').formcache('setCache', cache); $('form').formcache('setCaches', [cache, cache]);store()
Store all caches to sessionStorage or localStorage.
The plugin will do this automatically when a form control changed, or the window unloaded.
clear()
Clear all caches.
destroy()
Destroy the formcache instance, but keep the caches.
If you want to remove all caches, you can call clear method first and then call the destroy method.
No comments:
Post a Comment