Library to save form contents to LocalStorage
https://github.com/appleple/form-storage has not been maintained since 2020, so I made it.
npm install git+https://github.com/rsvzuiun/form-storage.gitimport FormStorage from 'form-storage';Copy dist/index.umd.js to your desired name.
<script src="path-to-index.umd.js"></script><script defer src="https://cdn.jsdelivr.net/gh/rsvzuiun/form-storage/dist/index.umd.js"></script>const storage = new FormStorage("form",
{
name: "unique-name",
includes: ['[class="in"]'],
ignores: ['[class="out"]']
});FormStorage.constructor()- 1st argument: CSS selectors to target
HTMLFormElement - 2nd argument:
name: Key when savig to LocalStorageignores: Array of CSS selectors to ignoreElementincludes: Array of CSS selectors to includeElement
- 1st argument: CSS selectors to target
storage.save(): Save the current form content to LocalStoragestorage.apply(): Load the state from LocalStorage and apply it to the formstorage.clear(): Remove the state from LocalStoragestorage.addEventListener(...): ApplyaddEventListenerforHTMLFormElementstorage.addChildrenEventListener(...): ApplyaddEventListenerfor allElements[]based onignoresandincludes