Garlic.js allows you to automatically persist your forms' text field values locally, until the form is submitted. This way, your users don't lose any precious data if they accidentally close their tab or browser.
It strives to have a javascript agnostic interface for UI/UX developers that might want to use it. Just add some data-persist="garlic"
in your form tags, and you're good to go!
×
New!
Have a look to Garlicjs little brother (or sister, as you want), Parsley.js: validate all your forms frontend without writing a single line of javascript!
<!--[if lte IE 7]>
<script src="https://raw.github.com/mattpowell/localstorageshim/master/localstorageshim.min.js" type="text/javascript"></script>
<![endif]-->
<script src="https://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="garlic.js"></script>
<script src="jquery.js">
<script src="garlic.js">
data-persist="garlic"
to the forms you want to auto-persist<form data-persist="garlic" method="POST">
Hey, all doc is not fully here. There are some useful config parameters in Garlic code, better directly have a look there! ;)
class="garlic-auto-save"
class!data-destroy="false"
(don't work on inputs separately, only on whole form inputs)
data-domain="true"
<script type="text/javascript">
$( '[rel=persist]' ).garlic();
</script>
<script type="text/javascript">
$( 'input.no_good' ).garlic( 'destroy' );
</script>
onRetrieve
callback:
<script type="text/javascript">
$( 'input.no_good' ).garlic( {
onRetrieve: function ( elem, retrievedValue ) {
console.log( 'The retrieved value for ' + elem.name() + ' is : ' + retrievedValue );
}
} );
</script>
onPersist
callback:
<script type="text/javascript">
$( 'input.no_good' ).garlic( {
onPersist: function ( elem, storedValue ) {
console.log( 'The persisted value for ' + elem.name() + ' is : ' + storedValue );
}
} );
</script>
<script type="text/javascript">
$( '#form' ).garlic( {
getPath: function ( $elem ) {
return $elem.attr( 'id' );
}
} );
</script>
© @guillaumepotier 2012 @wisembly