medabida / savy

Ultra-light jQuery plugin that automatically saves form values in the client side and restore them on your next visit
MIT License
22 stars 16 forks source link
javascript jquery localstorage

Savy

an ultra-light jQuery plugin that automatically saves form values in the client side (using HTML5 localStorage) and restore them on your next visit. A great solution to prevent data loss in case the browser is refreshed or the page is suddenly closed.

Supported elements:

How to use:

  1. Include jquery and Savy JS files

    <script src="https://github.com/medabida/savy/raw/master/jquery.js"></script>
    <script src="https://github.com/medabida/savy/raw/master/savy.min.js"></script>
  2. Create the following HTML element (each element must have a unique ID)

    <form action="foo.php">
      First name:<br>
      <input id="fname" type="text" class="auto-save" name="firstname" value="Mickey">
      <br>
      Last name:<br>
      <input id="lname" type="text" class="auto-save" name="lastname" value="Mouse">
    </form>
  3. initialize Savy

    $('.auto-save').savy('load');
    
    // you can pass a function to be called when savy is finished loading.
    $('.auto-save').savy('load',function(){
     console.log("All data from savy are loaded");
    });
  4. destroy Savy

    $('.auto-save').savy('destroy');
    
    // you can pass a function to be called when savy is destroyed.
    $('.auto-save').savy('destroy',function(){
     console.log("All data from savy are destroyed");
    });

TODO:

Compatibility:

License:

Released under the MIT license