Skip to main content

FormSaveController

Purpose

Save the value of a form and all of its inputs to LocalStorage, and restore it, at will.

Actions

ActionPurpose
saveSave the contents of the form to localstorage
restoreRestore the form to its previous state from localstorage
clearClear any saved state from localstorage

Targets

TargetPurposeDefault
---

Classes

ClassPurposeDefault
---

Values

ValueTypeDescriptionDefault
idStringThe unique ID of this form on the page. This combined with the current URL will allow multiple forms on the same page to all save.The ID of the controller root element, or throw an error an ID is not found and this is not specified
restoreOnLoadBooleanWhether the controller should try to restore any previous state when the controller connectstrue
clearOnSubmitBooleanWhether the controller should clean out the saved value when the form submitstrue

Events

EventWhenDispatched onevent.detail
form-save:clearedWhen the form is cleared, either by submit or when triggered by an actionThe controller root element (the form)-
form-save:save:successWhen the form saves successfullyThe controller root element (the form)-
form-save:restore:successWhen the form restores values successfullyThe controller root element (the form)-
form-save:restore:emptyWhen a restore is triggered, but there is nothing in localstorage to restoreThe controller root element (the form)-

Side Effects

If the clearOnSubmit value is set to true, a submit event listener will be installed on the form.

How to Use