storage-form
Examples
storage-form is a custom element that can edit and store the
values in some storages.
See HTML souce.
To enable storage-form, you need to register the custom
storage-elements.
Then, you can edit and store the foo value in the
localStorage.
the storage is selected by storage-area attribute. The
storage-area attribute can be one of the following values:
local-storagelocalStorage as a storage.session-storagesessionStorage as a storage.chrome-localchrome.storage.local as a storage.chrome-syncchrome.storage.sync as a storage.
Some elements are supported. You can use input,
select, textarea and output elements.
The name attribute of the element is used as a key of the
storage.
The below example shows the supported elements. These sources are in the
storage-form element.
if checked, the value of checkbox-sample1 is on,
otherwise the value is deleted.
If checked, the value of radio-sample is the value.
type=color:
type=date:
textarea:
Note:
type=button/submit/reset/image/hidden
are ignored.
If you have multiple elements with the same name, the value of
the elements are synchronized.
The following example named foo elements are synchronized.
Note: input type=color and input type=range does not
work right in the synchronization. They always force to set the default value,
because these types can not set the unset value like empty string in
type=date.
Like <form>, invalid values are not stored. The validity is
checked by the constraint attributes, such as required and
pattern, and by setCustomValidity(). Other valid
values in the same storage-form are still stored.
The validity is checked after the input or
change event has propagated, so a listener on an ancestor, even
one outside the storage-form, can set a custom validity. A
skipped value is stored on a later edit in the same
storage-form once it is valid, e.g. when the conflicting value is
fixed.
After each write, a storage-form-write event is dispatched from
the storage-form, with the names written and the names skipped as
invalid in event.detail. A skipped name is reported again on each
later edit in the form, until its value is stored, restored or overwritten.
Mono storage controls such as storage-input dispatch the event
too, but store a skipped value only on a later edit of the control itself.
To store invalid values too, add the novalidate attribute to the
storage-form, or to a mono storage control such as
storage-input.
You can switch the storage area with with javascript using
storage-form#storageArea property.
And you can also switch the name of binding target of the storage entry
storage-form#name property.
You can use support custom elements for some utilities.
storage-input, storage-select,
storage-textarea, storage-output
storage-input is a custom element that is shorthand for the
single <input> element in the storage-form.
The following example is the same as the above example:
storage-select, storage-textarea and
storage-output are the same as storage-input.
area-select,
storage-area-select
You can change the stored area for the foo's value using an
area-select element.
storage-area-select is not only the same as
area-select, but also it is like a mono storage select element.
So that it remembers the value in the storage.
storage-usageYou can show the storage usage using storage-usage element.
The storage-area attribute can be omitted, if
storage-usage element was put in the
storage-form element,