diff --git a/input/tangy-checkboxes-dynamic.js b/input/tangy-checkboxes-dynamic.js index 53ed4784..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,18 +170,33 @@ 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) } } + 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.value + this.dispatchEvent(new CustomEvent('change')) + } + } window.customElements.define(TangyCheckboxesDynamic.is, TangyCheckboxesDynamic);