Skip to content

Instantly share code, notes, and snippets.

View rosemulazada's full-sized avatar
:shipit:
tumi mundo-ing

Rose Mulazada rosemulazada

:shipit:
tumi mundo-ing
View GitHub Profile
@rosemulazada
rosemulazada / script.js
Last active June 8, 2024 14:24
SCALABLE: Save form data to localStorage and auto-complete on refresh
// With the help of Jeremy Keith, I was able to create a fully scalable code sample that you can copy-paste into your project.
// It will save the user input value on blur, this includes radio buttons, checkboxes and date inputs besides regular text/number inputs.
// The only condition is that you give the form element on your page a data-attribute of data-form-topic="foo".
// This code snippet saves the data-attribute as the key to the localStorage, and the value of it will be an object with key/value pairs of the respective inputs name and value.
// Please refer to this gist somewhere in your code if you use it :)
// Happy coding!
// VARIABLE DECLARATIONS
// objects
let savedData = {};