Save Form Changes In Local Storage – form-storage

Category: Form , Javascript , Recommended | November 9, 2020
Views Total:286 views
Official Page:Go to website
Last Update:November 9, 2020


Save Form Changes In Local Storage – form-storage


form-storage is a small JavaScript library to store the current values of your form fields in the local storage to prevent data loss.

The saved values will be automatically restored any time when needed such as refresh, next visit, etc.

See also:

How to use it:

Install the form-storage via package managers:

# Yarn
$ yarn add form-storage
$ npm install form-storage --save

Import the library as a module.

// ES 6
import FormStorage from 'form-storage';

Or directly include the JavaScript file ‘form-storage.js’ on the webpage.

<script src="form-storage.js"></script>

Apply the form-storage to your HTML form.

var formStorage = new FormStorage('.js-form');

Save the current form status in the local storage.;

You can specify an array of form fields to include or exclude.

var formStorage = new FormStorage('.js-form',{
    ignores: [],
    includes: [],

Create a checkbox to save data before submitting.

  <input type="checkbox" class="js-persist" />
  Allow saving form-data to localstorage.
var formStorage = new FormStorage('.js-form',{
    checkbox: '.js-persist'

Customize the localstorage name.

var formStorage = new FormStorage('.js-form',{
    name: 'form-storage'

Clear the stored data.



v1.3.5 (11/09/2020)

  • Updated

v1.3.3 (11/12/2019)

  • Fixed for IE


  • added getState and applyState medhod

You Might Be Interested In:

Leave a Reply