• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    JavaScript
  • Created almost 14 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Remember and restore form state using localStorage

jQuery form remember state plugin

Version: 1.4.1

When called on a form element, localStorage is used to remember the values that have been input up to the point of either saving or unloading. (closing window, navigating away, etc.) If localStorage isn't available, nothing is bound or stored.

By default, the plugin looks for an element with a class of remember_state within the form to show a note indicating there is stored data that can be repopulated by clicking on the anchor within the remember_state container. If the element doesn't exist, it is created and prepended to the form. You can override the selector and the HTML that is prepended in the options object you pass to the plugin.

Options

clearOnSubmit: true // Removes localStorage object when form submitted. Default is true
noticeDialog: $("<div />").html("<a href=\"#\">Restore</a>") // A newly created HTML element to represent the notice box prepended to the form. Must include an anchor for the user to choose to restore state
noticeSelector: ".remember_state" // If your noticeDialog already exists in the form, pass its selector here and clear out the noticeDialog option by setting it to false.
noticeConfirmSelector: "a" // Selector to use relative to the notice dialog to bind the confirm action to.
noticeCancelSelector: "" // Selector to use relative to the notice dialog to bind the cancel action to.
objName: "unique_form_name" // Specify a name for the localStorage object. If none is supplied, the form's ID will be used. If no ID is available, the plugin will fail, issuing a log explaining why.
ignore: null // Supply an array of name attributes for form controls that you'd like to ignore.

Usage

$("form").rememberState("my_object_name");

To restore the saved form state manually rather than use a notice dialog:

$("form").rememberState("restoreState");

If you'd like to save the form's state manually, call the rememberState method on the form after you've initialized it and pass it a string of save, like this:

$("form").rememberState("save");

There is also a teardown method for removing the bound events for a particular form. Passing a second argument of true will also destroy the localStorage object for that form.

$("form").rememberState("destroy", true);

Notes

To trigger the deletion of a form's localStorage object from outside the plugin, trigger the reset_state event on the form element by using $("form").trigger("reset_state");

Latest site design by Daniel Ariza

More Repositories

1

modal

A basic jQuery modal plugin built around Hashrocket's usual modal needs.
JavaScript
23
star
2

graphite

Simple pie chart library using canvas
JavaScript
15
star
3

dummy_image

JS only dummy image
JavaScript
15
star
4

super_number

jQuery superNumber - Add spinner controls to inputs
JavaScript
12
star
5

selleck

Javascript templating
JavaScript
7
star
6

tcgscraper_cockatrice

TCGPlayer deck scraper for Cockatrice
JavaScript
5
star
7

jquery_conf_2012

Extensible jQuery Plugin Development
JavaScript
5
star
8

ac_codegen

Animal Crossing Code Generator
PHP
3
star
9

simple_rte

Simple RTE - a simple rich text editor jQuery plugin
JavaScript
3
star
10

GraphiteSVG

Graphing library written to use jQuery and RaphaelJS
JavaScript
3
star
11

vimcuts

Vim-style shortcuts for textareas in bookmarklet form.
JavaScript
3
star
12

hashrocket_defender

JavaScript
2
star
13

charLimit

jQuery character limit plugin
JavaScript
2
star
14

mtgjson_decks_to_cockatrice

MTGJSON Preconstructed Deck Files Converter for Cockatrice
JavaScript
2
star
15

jquery_pseudo_element

Get/set CSS properties on pseudo elements
JavaScript
2
star
16

brick_by_brick

A game based on crossword puzzles.
JavaScript
2
star
17

solitaire_checkers

Tiny canvas based game I wrote to pass the time the day before Christmas break.
JavaScript
2
star
18

firefox_skyscraper

A skyscraper "sculpted" in DOM and Firefox 3D view
JavaScript
2
star
19

shadowgate

NES Shadowgate
JavaScript
2
star
20

glitch_api_demo

Glitch API Demo
JavaScript
2
star
21

magic_scraper

HTML scraper for M:TG site
Ruby
1
star
22

mtg_card_generator

Javascript Canvas card generator
JavaScript
1
star
23

jaxjs_20120726

Canvas Demos
JavaScript
1
star
24

project_euler_ruby

A couple Project Euler problems
Ruby
1
star
25

nordic_ruby_2012

Lightning Talk: Cache those things!
JavaScript
1
star
26

html5up-strata-react

HTML5Up's Strata template as React components
CSS
1
star
27

word_munchers

Word Munchers using canvas and Javascript
JavaScript
1
star
28

simpleconversions

Backup of simpleconversions.com
PHP
1
star
29

harvest_bookmarklet

Keyboard shortcuts for the day view of Harvest
JavaScript
1
star
30

project_euler_python

Let's try Python!
Python
1
star
31

Yars_Revenge

JavaScript
1
star