Skip to content

Commit 17caa09

Browse files
committed
fix: update evaluation of :checked
1 parent 58d0e64 commit 17caa09

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

lib/entity/attributes.js

+21-15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class Attributes {
5656
await this.evaluateClass()
5757
await this.evaluateText()
5858
await this.evaluateValue()
59+
await this.evaluateChecked()
5960

6061
for (const attr of this.dynamicAttributes) {
6162
if (Attributes.CUSTOM_ATTRIBUTES.includes(attr)) continue
@@ -70,7 +71,8 @@ export class Attributes {
7071
if (attr === ':parent') this.evaluateParent()
7172
else if (attr === ':class') await this.evaluateClass()
7273
else if (attr === ':text') await this.evaluateText()
73-
else if ([':value', ':checked'].includes(attr)) await this.evaluateValue()
74+
else if (attr === ':value') await this.evaluateValue()
75+
else if (attr === ':checked') await this.evaluateChecked()
7476
else if (attr === ':each') await this.evaluateEach()
7577
else {
7678
if (!this.dynamicAttributes.includes(attr))
@@ -108,32 +110,36 @@ export class Attributes {
108110
try {
109111
const newText = await this.base._interpret(textExpr)
110112

111-
if (newText || newText == '') this.base.element.innerText = newText
113+
if (newText || newText == '') this.base.element.textContent = newText
112114
} catch (error) {
113115
this._handleError(':text', error)
114116
}
115117
}
116118

117119
async evaluateValue() {
120+
const valueExpr = this.base.element.getAttribute(':value')
121+
if (!valueExpr) return
118122
try {
119-
const valueExpr = this.base.element.getAttribute(':value')
123+
const newValue = await this.base._interpret(valueExpr)
120124

121-
if (valueExpr) {
122-
const newValue = await this.base._interpret(valueExpr)
123-
124-
if (this.base.element.value !== newValue && newValue != null)
125-
this.base.element.value = newValue
126-
}
125+
if (this.base.element.value !== newValue && newValue != null)
126+
this.base.element.value = newValue
127+
} catch (error) {
128+
this._handleError(':value', error)
129+
}
130+
}
127131

128-
const checkedExpr = this.base.element.getAttribute(':checked')
132+
async evaluateChecked() {
133+
const checkedExpr = this.base.element.getAttribute(':checked')
134+
if (!checkedExpr) return
129135

130-
if (checkedExpr) {
131-
const newValue = await this.base._interpret(checkedExpr)
136+
try {
137+
const isChecked = await this.base._interpret(checkedExpr)
132138

133-
if (newValue) this.base.element.checked = newValue
134-
}
139+
if (this.base.element.checked !== isChecked && isChecked != null)
140+
this.base.element.checked = isChecked
135141
} catch (error) {
136-
this._handleError(':value', error)
142+
this._handleError(':checked', error)
137143
}
138144
}
139145

0 commit comments

Comments
 (0)