menu/switch/dropdown: reset value to undefined when receiving a value that's not defined in values

This commit is contained in:
bordun 2021-04-21 16:58:31 +02:00
parent db165faa9f
commit 5d37ba109a
3 changed files with 15 additions and 15 deletions

View file

@ -300,17 +300,15 @@ class Menu extends MenuBase {
var i = this.getIndex(v)
this.value = this.values[i]
this.selected = i
DOM.each(this.menu, '.on', (el)=>{el.classList.remove('on')})
this.setLabel()
if (i !== -1) {
this.value = this.values[i]
this.selected = i
DOM.each(this.menu, '.on', (el)=>{el.classList.remove('on')})
DOM.get(this.menu, '.item')[i].classList.add('on')
this.setLabel()
}
if (options.send) this.sendValue()
if (options.sync) this.changed(options)

View file

@ -113,18 +113,17 @@ class Switch extends MenuBase {
var i = this.getIndex(v)
this.value = this.values[i]
DOM.each(this.widget, '.on', (el)=>{el.classList.remove('on')})
if (i !== -1) {
this.value = this.values[i]
DOM.each(this.widget, '.on', (el)=>{el.classList.remove('on')})
DOM.get(this.widget, 'value')[i].classList.add('on')
if (options.send) this.sendValue(this.value)
if (options.sync) this.changed(options)
}
if (options.send) this.sendValue(this.value)
if (options.sync) this.changed(options)
}
setCssVariables() {