Skip to content

Commit f66f21b

Browse files
authored
Merge pull request #1313 from sveltejs/gh-1270
fail validation if bound <select> has dynamic multiple attribute
2 parents 2cd4957 + dfc8462 commit f66f21b

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/validate/html/validateElement.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,20 @@ export default function validateElement(
102102
);
103103
}
104104

105-
checkTypeAttribute(validator, node);
105+
if (node.name === 'select') {
106+
const attribute = node.attributes.find(
107+
(attribute: Node) => attribute.name === 'multiple'
108+
);
109+
110+
if (attribute && isDynamic(attribute)) {
111+
validator.error(
112+
`'multiple' attribute cannot be dynamic if select uses two-way binding`,
113+
attribute
114+
);
115+
}
116+
} else {
117+
checkTypeAttribute(validator, node);
118+
}
106119
} else if (name === 'checked' || name === 'indeterminate') {
107120
if (node.name !== 'input') {
108121
validator.error(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[{
2+
"message": "'multiple' attribute cannot be dynamic if select uses two-way binding",
3+
"loc": {
4+
"line": 1,
5+
"column": 19
6+
},
7+
"end": {
8+
"line": 1,
9+
"column": 28
10+
},
11+
"pos": 19
12+
}]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<select bind:value :multiple>
2+
<option>1</option>
3+
<option>2</option>
4+
<option>3</option>
5+
</select>

0 commit comments

Comments
 (0)