name attribute on radio buttons with v-model: yes or no?
#14219
Replies: 1 comment 1 reply
-
|
Yeah this is actually a known behavior and you found the solution yourself - dont use Heres whats happening: When you use But when you also add Thats why:
<input type="radio" id="one" value="One" v-model="picked" />
<input type="radio" id="two" value="Two" v-model="picked" />The You only need |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hii.
To save your time: When making custom components with radio buttons and
v-model, should we includename? If not, can this be documented in https://vuejs.org/guide/essentials/forms.html#radio-1?I made a custom component that has a set of radio buttons with
v-model, and displayed the chosen value. Something like this:However I found that whenever I clicked a radio button, the displayed
pickedvalue changed, but the actual radio button did not get selected. If I click again, then it got selected.I tried all possible things to reproduce the error, including making a new project, removing CSS, making a duplicate of the component with only non-trivial stuff, but everything failed. I could produce the problem only in one page of my app and that too when I placed it in inside
<header>.Frustrated, I asked LLM and it told me:
(Not trying to praise LLM, but giving credit where due).
So I tried removing
nameattribute and it worked fine now! If I added back thenameattribute, the problem was back.The LLM refused to share links, but when I searched online for "Vue radio-button name v-model", I found this blog - https://williamhuster.com/radio-buttons-in-vue/. OP also faced the same problem and resolved it by removing
nameattribute.This is still a mystery to me and searching for "name" in https://vuejs.org/guide/essentials/forms.html#radio-1 does not show any information about whether we should include
nameattribute in radio buttons.So I'm wondering if this is a well known problem and if this can be documented in Vue's docs.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions