fix Select input not setting the correct value

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2019-12-09 14:14:01 +01:00
parent 93adf6d225
commit 44762c6e72
No known key found for this signature in database
GPG Key ID: B143FF27EF555D16

View File

@ -10,25 +10,16 @@ import { realType } from '../Functions';
export default class SelectInput extends DefaultInput {
public setValue(value: any) {
value = realType(value)
let opt:HTMLOptionElement|undefined = this.element.querySelector(`option[value="${value}"]`) || undefined
if (opt) {
this.element.value = value
return
}
opt = this.element.querySelector("option[selected]") || undefined
if (opt) {
this.element.value = opt.value
}
this.element.value = this.formatValue(value)
}
public formatValue(value: any): any {
if (typeof value !== "undefined" && value !== "") {
return realType(value)
}
const opt: HTMLOptionElement|undefined = this.element.querySelector("option[selected]") || undefined
const opt = this.element.querySelector("option[selected]") || undefined
if (opt) {
return opt.value
return (opt as HTMLOptionElement).value
}
throw Error(":O it should never come here")
}