Include the 'checked' property in snapshots and state resets.

This commit is contained in:
trading_peter 2022-05-05 09:53:08 +02:00
parent 8f0d9524ba
commit 7ca87b7bdd
2 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@tp/tp-form",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "tp-form.js",
"scripts": {

View File

@ -250,6 +250,7 @@ class TpForm extends LitElement {
for (let i = 0, li = this._origValues.length; i < li; ++i) {
const item = this._origValues[i];
item.control.value = this._copyValue(item.value || null, item.control);
item.control.checked = this._copyValue(item.checked || null, item.control);
if (typeof item.control.reset === 'function') {
item.control.reset();
}
@ -279,6 +280,7 @@ class TpForm extends LitElement {
for (let i = 0, li = this._origValues.length; i < li; ++i) {
const item = this._origValues[i];
item.value = item.control.value;
item.checked = item.control.checked;
}
this._snapshot = JSON.stringify(this.serialize());
@ -295,7 +297,7 @@ class TpForm extends LitElement {
}
// Store copy of original value in case we want to reset the form.
this._origValues.push({ control: target, value: this._copyValue(target.value, target) });
this._origValues.push({ control: target, value: this._copyValue(target.value, target), checked: this._copyValue(target.checked, target) });
// Stop propagation of the registration event.
// This allows for nested forms.
@ -433,4 +435,4 @@ class TpForm extends LitElement {
}
}
window.customElements.define('tp-form', TpForm);
window.customElements.define('tp-form', TpForm);