diff --git a/lib/entity/attributes.js b/lib/entity/attributes.js index b6439fe..883fec4 100644 --- a/lib/entity/attributes.js +++ b/lib/entity/attributes.js @@ -56,6 +56,7 @@ export class Attributes { await this.evaluateClass() await this.evaluateText() await this.evaluateValue() + await this.evaluateChecked() for (const attr of this.dynamicAttributes) { if (Attributes.CUSTOM_ATTRIBUTES.includes(attr)) continue @@ -70,7 +71,8 @@ export class Attributes { if (attr === ':parent') this.evaluateParent() else if (attr === ':class') await this.evaluateClass() else if (attr === ':text') await this.evaluateText() - else if ([':value', ':checked'].includes(attr)) await this.evaluateValue() + else if (attr === ':value') await this.evaluateValue() + else if (attr === ':checked') await this.evaluateChecked() else if (attr === ':each') await this.evaluateEach() else { if (!this.dynamicAttributes.includes(attr)) @@ -108,32 +110,36 @@ export class Attributes { try { const newText = await this.base._interpret(textExpr) - if (newText || newText == '') this.base.element.innerText = newText + if (newText || newText == '') this.base.element.textContent = newText } catch (error) { this._handleError(':text', error) } } async evaluateValue() { + const valueExpr = this.base.element.getAttribute(':value') + if (!valueExpr) return try { - const valueExpr = this.base.element.getAttribute(':value') + const newValue = await this.base._interpret(valueExpr) - if (valueExpr) { - const newValue = await this.base._interpret(valueExpr) - - if (this.base.element.value !== newValue && newValue != null) - this.base.element.value = newValue - } + if (this.base.element.value !== newValue && newValue != null) + this.base.element.value = newValue + } catch (error) { + this._handleError(':value', error) + } + } - const checkedExpr = this.base.element.getAttribute(':checked') + async evaluateChecked() { + const checkedExpr = this.base.element.getAttribute(':checked') + if (!checkedExpr) return - if (checkedExpr) { - const newValue = await this.base._interpret(checkedExpr) + try { + const isChecked = await this.base._interpret(checkedExpr) - if (newValue) this.base.element.checked = newValue - } + if (this.base.element.checked !== isChecked && isChecked != null) + this.base.element.checked = isChecked } catch (error) { - this._handleError(':value', error) + this._handleError(':checked', error) } }