FormStorage – A JavaScript library stores the form-data to the localstorage and retrieves t…

Quick start

Using CDN

You can easily start by using CDN.

Add the following description in the
tag of the web page you want to use FormStorage.

You can also bundle the library with Browserify/Webpack

npm install form-storage --save
import FormStorage from 'form-storage'

Wrap the elements you want to apply ScrollSuggest like below

Write the following script

new FormStorage('.js-scrollable', {
  name: 'form-storage', //localstorage name
  ignores: [ // The selectors specified here, won't be stored in the storage.
    '[type="password"]'
  ],
  checkbox: '.js-persist' //if the selector specified here is checked, the form data will be stored.
});

Options

Some options are available when making new instances like below.

var storage = new FormStorage('.js-scrollable', {
  name: 'form-storage', //localstorage name
  ignores: [ // The selectors specified here, won't be stored in the storage.
    '[type="password"]', '.js-ignore'
  ],
  checkbox: '.js-persist' //if the selector specified here is checked, the form data will be stored.
});

For your reference, below is the list of the options available.

NameDefaultDescription
name‘form’localstorage name to be used
ignores[]Selectors which won’t be saved on the storage
includes[]When specified, only selectors specified here will be saved
checkboxnull When this checkbox is checked, the form data will be saved before submitting
and the form data will be restored when the page is loaded.

Methods

You can also use some methods from the instances like below

var storage = new FormStorage('.js-scrollable', {
  name: 'form-storage', //localstorage name
  ignores: [ // The selectors specified here, won't be stored in the storage.
    '[type="password"]', '.js-ignore'
  ],
  checkbox: '.js-persist' //if the selector specified here is checked, the form data will be stored.
});
storage.save(); //using the method
NameDescription
saveSave the form-data on the localstorage
applyFill the form from the localstorage
clearRemove the localstorage

Join development on

GitHub

License

Echo JS责编内容来自:Echo JS (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » FormStorage – A JavaScript library stores the form-data to the localstorage and retrieves t…

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录