mirror of
https://github.com/dzeiocom/FormManager.git
synced 2025-04-22 10:52:16 +00:00
fix Select input not setting the correct value
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
93adf6d225
commit
44762c6e72
@ -10,25 +10,16 @@ import { realType } from '../Functions';
|
|||||||
export default class SelectInput extends DefaultInput {
|
export default class SelectInput extends DefaultInput {
|
||||||
|
|
||||||
public setValue(value: any) {
|
public setValue(value: any) {
|
||||||
value = realType(value)
|
this.element.value = this.formatValue(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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public formatValue(value: any): any {
|
public formatValue(value: any): any {
|
||||||
if (typeof value !== "undefined" && value !== "") {
|
if (typeof value !== "undefined" && value !== "") {
|
||||||
return realType(value)
|
return realType(value)
|
||||||
}
|
}
|
||||||
const opt: HTMLOptionElement|undefined = this.element.querySelector("option[selected]") || undefined
|
const opt = this.element.querySelector("option[selected]") || undefined
|
||||||
if (opt) {
|
if (opt) {
|
||||||
return opt.value
|
return (opt as HTMLOptionElement).value
|
||||||
}
|
}
|
||||||
throw Error(":O it should never come here")
|
throw Error(":O it should never come here")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user