From 7ca87b7bdd66859f6955bde7d7956b380b59547a Mon Sep 17 00:00:00 2001 From: trading_peter Date: Thu, 5 May 2022 09:53:08 +0200 Subject: [PATCH] Include the 'checked' property in snapshots and state resets. --- package.json | 2 +- tp-form.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d4ca9ea..e4e3074 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tp/tp-form", - "version": "1.0.0", + "version": "1.0.1", "description": "", "main": "tp-form.js", "scripts": { diff --git a/tp-form.js b/tp-form.js index 223c0e0..76eec7b 100644 --- a/tp-form.js +++ b/tp-form.js @@ -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); \ No newline at end of file +window.customElements.define('tp-form', TpForm);