And if you use a different refs (dynamically) for each group of radio buttons ?
return value of selected radio button with v-for
I have a radio group for a form created with v-for. I need to return the value of the selected button in a function. Here's what I've tried:
Use the v-model value. The issue is it returns the value of the button previously checked. This is due to the function using the current form value before it updates. I tried to figure out how to delay it or call the function after click with no luck, then was reminded of refs.
So I added the ref not realizing it applies the same ref to all inputs. Which of course it does, but this it returns an array.
How do I choose the selected button? Is there a way to apply the ref only to the selected button?
<div v-for="mealService in mealServices" :key="mealService.id">
<input @click="setActiveMealService" type="radio" name="meal_type"
:id="mealService.meal_type_id"
:value="mealService.meal_type_id"
v-model="form.meal_type_id"/>
<label :for="mealService.meal_type_id">{{ mealService.meal_type.name }}</label>
</div>
Please or to participate in this conversation.