1๐
โ
Two ways to get rid from the problem you are facing :
-
Use
value-field
andtext-field
attributes in your<b-form-checkbox-group>
element.Live Demo :
new Vue({ el: '#app', data() { return { formData: { selectedBusinessLines: [], businessLines: [ {id: 1, name: 'Cars'}, {id: 2, name: 'Trucks'}, {id: 3, name: 'Buses'} ] } } } })
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.min.js"></script> <script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script> <div id="app"> <b-form-checkbox-group v-model="formData.selectedBusinessLines" :options="formData.businessLines" value-field="id" text-field="name"> </b-form-checkbox-group> </div>
-
:options
will show the options based on thetext
key. Hence, You can tweak the objects which will have the keys astext
andvalue
.
-
value
: The selected value which will be set onv-model
. -
text
: Display text, or html Display basic inline html.Live Demo :
new Vue({ el: '#app', data() { return { formData: { selectedBusinessLines: [], businessLines: [ {value: 1, text: 'Cars'}, {value: 2, text: 'Trucks'}, {value: 3, text: 'Buses'} ] } } } })
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.min.js"></script> <script src="https:////unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script> <div id="app"> <b-form-checkbox-group v-model="formData.selectedBusinessLines" :options="formData.businessLines"> </b-form-checkbox-group> </div>
You can have a look in this official documentation of <b-form-checkbox-group>
0๐
You need to structure your formData.businessLines that you use as options differently, like:
formData.businessLines = [
{ text: 'Cars', value: 1 },
{ text: 'Trucks', value: 2 },
{ text: 'Buses', value: 3 },
]
Source:stackexchange.com