sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.19k stars 4.09k forks source link

Svelte3 bind:checked and radio input #2300

Closed dmitry-kurmanov closed 5 years ago

dmitry-kurmanov commented 5 years ago

Hello!

I've got the compile time error with the checked binding:

(svelte plugin) ValidationError: 'checked' binding can only be used with <input type="checkbox">

But what about type="radio" ? checked is valid attribute for it, please check: https://developer.mozilla.org/ru/docs/Web/HTML/Element/Input/radio

It make sense when we have several radio inputs with the same name.

Thanks!

PS svelte3 is awesome :)

dmitry-kurmanov commented 5 years ago

According to the source code it seems to be ok : https://github.com/sveltejs/svelte/blob/21d56c9ee32f0a9b76e5e522943c818c3e36f9d3/src/compile/nodes/Element.ts#L512

I use "3.0.0-beta.20" version

Conduitry commented 5 years ago

With radio button inputs, you can use bind:group - https://v3.svelte.technology/tutorial/group-inputs

The line you're pointing to is actually the test for group bindings. Its error message refers to checked though, and that should be fixed.

bind:checked on radio buttons is something that's come up before (e.g, #1104) and the decision then was that this was too complicated to be worth implementing. bind:group should be able to give you just about everything you need.

dmitry-kurmanov commented 5 years ago

I think that with the new error message we will not have any problem with it. Thanks.