0.0.1 • Published 7 years ago

jquery-storeify v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

jquery-storeify

A jQuery plugin that saves forms as JSON using Web Storage

jquery-storeify consolidates a form and will take each of its fields name and values and save it to webstorage to a single JSON object using the form's name as the storage key, each input name as the JSON s key and the input value as the JSON's value. You may use storeify to store a form by button click or before page unload event.

Setup

1. Pull in the script:

You may either clone/download the script from this repo:

	<script type="text/javascript" src="dist/storeify.min.js"></script>

or install via npm:

	npm install jquery-storeify

then require it in your main js file:

	require('jquery-storeify');

2. Name your form and it's inputs

Be sure your form elements and its text fields have unique name attributes defined or else you will have undefined key values saved. Be sure to give radio buttons and checkboxes some values as well. Since these can have the non unique names/duplicates, jquery-storeify relies on its values to determine which one to repopulate.

  <form name="applicationForm">
      <input name="name" type="text"/>
      <input name="email" type="email"/>
      //etc.
  </form>

3. Use:

Default Use:

	$('form').storeify();

Default Options

By default jquery-storeify's options are:

  • storageType : "sessionStorage"
  • ignore: [submit,password,hidden]
  • saveOnUnload: true
  • saveButtonSelector: .storeify
  • done: null

Custom Options Use Example:

You may override the defaults by passing your custom options:

  • storageType : either "sessionStorage"or "localStorage"
  • ignore: an array of input types/name to ignore from saving.
  • saveOnUnload: either true or false. If set to false then jquery-storefiy can be called via click event on the selector you define under the saveButtonSelector option.
  • saveButtonSelector: the jQuery selector of the button that calls jquery-storeify plugin if saveOnUnload option is set to false. Be sure that the button is a child of the form.
  • done: callback function for when the plugin finishes saving forms.

	
    $('form').storeify({

		storageType: "localStorage",
		ignore: ['submit','hidden'],
		saveOnUnload: false,
		saveButtonSelector: ".save-form",
		done: function(){
			//note that alert doesnt work onUnload event in some browsers
			alert("Storeified:D");
		}

	});

Please report bugs under issues. Pull requests always welcome.