Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUESTION: How do I v-model to a group of radio buttons? #7

Open
camdecoster opened this issue May 9, 2022 · 3 comments
Open

QUESTION: How do I v-model to a group of radio buttons? #7

camdecoster opened this issue May 9, 2022 · 3 comments

Comments

@camdecoster
Copy link

I'm using the CFormCheck component to allow the user to select an option, but I can't figure out how to get the value of the selected button back to my state variable. Should I be setting the model-value attribute? If so, how does that work? Every time I try to set it, the attribute takes on the value true no matter what value I pass in. Is there an example on the documentation site? Thank you.

Example:

<CFormCheck
  id="inlineCheckbox1"
  v-model="cloudSave"
  inline
  type="radio"
  name="inlineRadioOptions"
  label="Local"
  model-value="cloudSave"
/>
@camdecoster
Copy link
Author

I think the issue has to do with this line and this line. When the change event happens, the checked status is returned via the 'update:modelValue' event. Eventually, the checked status will be true and won't change because the value returned by the event will always be true (because the current button state is true).

@sametsafak
Copy link

sametsafak commented Jun 14, 2022

I hope form components themselves and the docs will be updated.
I am getting radios' value with an ugly trick like the below about this issue. I hope it helps.

<CFormCheck
  type="radio"
  name="my-radio"
  id="radio1"
  label="Radio 1"
  value="1"
  :checked="radioModel === '1'"
  @click="radioModel = $event.target.value"
/>
<CFormCheck
  type="radio"
  name="my-radio"
  id="radio2"
  label="Radio 2"
  value="2"
  :checked="radioModel === '2'"
  @click="radioModel = $event.target.value"
/>

@JediKnightChan
Copy link

Well imagine 10 years passed but radios are not working with vue normally still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants