You can create an array of objects that can be saved to localStorage using JSON.stringify()
during save, and JSON.parse()
during retrieval to return string to array.
What you save will depend a bit on your UI needs.
The very simplest format of this array can be easily obtained using jQuery serializeArray()
. If you need more detail like label value, display settings etc you would need to create your own objects for the array
Thus you could do:
var data = $('#formID').serializeArray();
localStorage.setItem('myFormData', JSON.stringify( data));
Then on page load, retrieve string from localStorage, return it to array using JSON.parse
and loop over array to create your fields