renderDropdown = (id) => {
const select = html`<select multiple></select>`
let dropdown = new Choices(select, {
removeItemButton: true,
allowHTML: true,
choices: options
})
const container = html`<div>${select.closest(".choices")}</div>`
function getValue() {
let currentValue = dropdown.getValue(true)
console.log(`get - id:[${id}] v:[${currentValue}]`)
return currentValue;
}
function setValue(newValue) {
let currentValue = container.value
console.log(`set - id:[${id}] c:[${currentValue}] n:[${newValue}]`)
if(currentValue.toString() !== newValue.toString()) {
console.log(`updating - id:[${id}] v:[${newValue}]`)
dropdown.setChoiceByValue(newValue)
console.log(`updated - id:[${id}]`)
}
}
Object.defineProperty(container, "value", {
get: getValue,
set: setValue
});
return container
}