Skip to content

Commit 23ecd3d

Browse files
committed
show an extra bind checked error when a radio type
1 parent 9e5fe33 commit 23ecd3d

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

documentation/docs/03-template-syntax/12-bind.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Since 5.6.0, if an `<input>` has a `defaultValue` and is part of a form, it will
9595
9696
## `<input bind:checked>`
9797

98-
Checkbox can be bound with `bind:checked`:
98+
Checkbox inputs can be bound with `bind:checked`:
9999

100100
```svelte
101101
<label>

packages/svelte/src/compiler/phases/2-analyze/visitors/BindDirective.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function BindDirective(node, context) {
7070
e.bind_invalid_target(
7171
node,
7272
node.name,
73-
`<input type="checkbox"> - for <input type="radio">, use 'group' binding`
73+
`<input type="checkbox">${type?.value[0].data === 'radio' ? ` — for <input type="radio">, use 'group' binding` : ''}`
7474
);
7575
}
7676

packages/svelte/tests/validator/samples/binding-input-checked/errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"code": "bind_invalid_target",
4-
"message": "`bind:checked` can only be used with <input type=\"checkbox\"> - for <input type=\"radio\">, use 'group' binding",
4+
"message": "`bind:checked` can only be used with <input type=\"checkbox\">",
55
"start": {
66
"line": 5,
77
"column": 7
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "bind_invalid_target",
4+
"message": "`bind:checked` can only be used with <input type=\"checkbox\"> — for <input type=\"radio\">, use 'group' binding",
5+
"start": {
6+
"line": 5,
7+
"column": 20
8+
},
9+
"end": {
10+
"line": 5,
11+
"column": 38
12+
}
13+
}
14+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
let foo;
3+
</script>
4+
5+
<input type="radio" bind:checked={foo}>

0 commit comments

Comments
 (0)