Allow setting value to undefined
This commit is contained in:
parent
f55e420cbc
commit
6c3db0456e
1 changed files with 8 additions and 4 deletions
|
@ -385,12 +385,16 @@ export class BetterSelect extends HTMLElement {
|
||||||
|
|
||||||
get value() { return this.#value.value }
|
get value() { return this.#value.value }
|
||||||
set value(value) {
|
set value(value) {
|
||||||
for (const option of this.options) {
|
if (value === undefined) {
|
||||||
|
this.clear()
|
||||||
|
} else {
|
||||||
|
for (const option of Array.from(this.options)) {
|
||||||
if (option.value === String(value)) {
|
if (option.value === String(value)) {
|
||||||
this.setValue(option.value, option.innerText)
|
this.setValue(option.value, option.innerText)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
throw `No option with value ${value}`
|
throw `No option with value ${value}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue