I’m new using Vue and specifically Bootstrap Vue and I’m trying to build a form with multiple radio groups.
My problem is that when I change the value in one of them the others don’t change their values (this was checked with Vue DevTools) but visually it looks like none of the values are selected
I don’t know what is wrong with my approach
I post here a simplified version of the code looking for some help, thanks in advance:
JavaScript
x
45
45
1
<template>
2
<div>
3
4
<b-form-group label="Radio group 1" v-slot="{ ariaDescribedby }">
5
<b-form-radio-group
6
id="radio-group-1"
7
v-model="selected1"
8
:options="options1"
9
:aria-describedby="ariaDescribedby"
10
name="radio-options"
11
></b-form-radio-group>
12
13
</b-form-group>
14
<b-form-group label="Radio Group 2" v-slot="{ ariaDescribedby }">
15
<b-form-radio-group
16
id="radio-group-2"
17
v-model="selected2"
18
:options="options2"
19
:aria-describedby="ariaDescribedby"
20
name="radio-options"
21
></b-form-radio-group>
22
</b-form-group>
23
24
</div>
25
</template>
26
27
<script>
28
export default {
29
data() {
30
return {
31
selected1: 'first',
32
options1: [
33
{ text: 'First', value: 'first' },
34
{ text: 'Second', value: 'second' },
35
],
36
selected2: 'one',
37
options2: [
38
{ text: 'One', value: 'one' },
39
{ text: 'Two', value: 'two' },
40
]
41
}
42
}
43
}
44
</script>
45
Advertisement
Answer
Since both <b-form-radio-group>
elements have the same name, “radio-options”, visually they are treated like one group. The different v-model
would still function correctly but this isn’t what you want visually. Give the second group a different name:
JavaScript
1
8
1
<b-form-radio-group
2
id="radio-group-2"
3
v-model="selected2"
4
:options="options2"
5
:aria-describedby="ariaDescribedby"
6
name="radio-options2"
7
></b-form-radio-group>
8
Here I changed it to radio-options2
.