Skip to content

Commit

Permalink
fix: update evaluation of :checked
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenrui committed Feb 14, 2024
1 parent 58d0e64 commit 17caa09
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions lib/entity/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 17caa09

Please sign in to comment.