From 566fa35edb6d70d90488fc9fb091343a389b664b Mon Sep 17 00:00:00 2001 From: "Chris E. Kelley" Date: Thu, 3 Oct 2019 15:28:25 +0200 Subject: [PATCH 1/3] Get value of tangy-checkboxes for t-c-dynamic --- input/tangy-checkboxes-dynamic.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/input/tangy-checkboxes-dynamic.js b/input/tangy-checkboxes-dynamic.js index 53ed4784..ea71add5 100644 --- a/input/tangy-checkboxes-dynamic.js +++ b/input/tangy-checkboxes-dynamic.js @@ -179,9 +179,23 @@ class TangyCheckboxesDynamic extends PolymerElement { console.log("e: " + e) } } + let newValue = [] + checkboxesEl.addEventListener('change', this.onCheckboxesClick.bind(this)) + newValue = checkboxesEl.getProps() + if (!this.value || (typeof this.value === 'object' && this.value.length < newValue.length)) { + this.value = newValue + } containerEl.appendChild(checkboxesEl) } + onCheckboxesClick(event) { + let newValue = [] + let el = this.shadowRoot.querySelector('tangy-checkboxes') + newValue = el.getProps() + this.value = newValue + this.dispatchEvent(new CustomEvent('change')) + } + } window.customElements.define(TangyCheckboxesDynamic.is, TangyCheckboxesDynamic); From 7836752f08f937f02b111d1da27029193feb8f6d Mon Sep 17 00:00:00 2001 From: "Chris E. Kelley" Date: Thu, 3 Oct 2019 17:00:34 +0200 Subject: [PATCH 2/3] Copy the value array from tangy-checkboxes to t-c-dynamic --- input/tangy-checkboxes-dynamic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input/tangy-checkboxes-dynamic.js b/input/tangy-checkboxes-dynamic.js index ea71add5..6c9338fc 100644 --- a/input/tangy-checkboxes-dynamic.js +++ b/input/tangy-checkboxes-dynamic.js @@ -192,7 +192,7 @@ class TangyCheckboxesDynamic extends PolymerElement { let newValue = [] let el = this.shadowRoot.querySelector('tangy-checkboxes') newValue = el.getProps() - this.value = newValue + this.value = newValue.value this.dispatchEvent(new CustomEvent('change')) } From 987381d407bd219643b5f32850ebaea9b9da99ec Mon Sep 17 00:00:00 2001 From: "Chris E. Kelley" Date: Sun, 6 Oct 2019 22:19:47 +0200 Subject: [PATCH 3/3] Sending form id as name in order to persist it. --- input/tangy-checkboxes-dynamic.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/input/tangy-checkboxes-dynamic.js b/input/tangy-checkboxes-dynamic.js index 6c9338fc..399756e3 100644 --- a/input/tangy-checkboxes-dynamic.js +++ b/input/tangy-checkboxes-dynamic.js @@ -146,7 +146,7 @@ class TangyCheckboxesDynamic extends PolymerElement { } if (!excludeOption) { let option = { - value: item[name], + name: item[name], innerHTML: item[innerHTML] } that.optionsList.push(option) @@ -170,11 +170,12 @@ class TangyCheckboxesDynamic extends PolymerElement { let containerEl = this.shadowRoot.querySelector('.container') let checkboxesEl = document.createElement('tangy-checkboxes') for (let option of this.optionsList) { - let checkbox = document.createElement('option') - checkbox.name = option.value - checkbox.innerHTML = option.innerHTML + let optionEl = document.createElement('option') + optionEl.name = option.name + optionEl.value = option.name + optionEl.innerHTML = option.innerHTML try { - checkboxesEl.appendChild(checkbox) + checkboxesEl.appendChild(optionEl) } catch (e) { console.log("e: " + e) }