diff --git a/frontend/src/ts/utils/dom.ts b/frontend/src/ts/utils/dom.ts index 7955d0378..7c5d808ff 100644 --- a/frontend/src/ts/utils/dom.ts +++ b/frontend/src/ts/utils/dom.ts @@ -450,11 +450,19 @@ export class ElementWithUtils { return new ElementWithUtils(wrapperElement as T); } + private hasValue(): this is ElementWithUtils { + return ( + this.native instanceof HTMLInputElement || + this.native instanceof HTMLTextAreaElement || + this.native instanceof HTMLSelectElement + ); + } + /** * Set value of input or textarea to a string. */ setValue(this: ElementWithUtils, value: string): this { - if (this.native instanceof HTMLInputElement) { + if (this.hasValue()) { this.native.value = value; } return this as unknown as this; @@ -465,10 +473,10 @@ export class ElementWithUtils { * @returns The value of the element, or undefined if the element is not an input or textarea. */ getValue(this: ElementWithUtils): string | undefined { - if (!(this.native instanceof HTMLInputElement)) { - return undefined; + if (this.hasValue()) { + return this.native.value; } - return this.native.value; + return undefined; } /**