I have a Vue JS app that uses a Vuetify checkbox. I am unable to set the initial value to checked.
<v-checkbox
v-else-if="input.type == 'checkbox'"
false-value="0"
true-value="1"
v-model="input.val"
:error-messages="form.errors[field]"
>
When input.val
is equal to 1
i expect the checkbox to start off checked. However the checkbox will not start off checked.
I have also tried adding the props:
:value="input.val"
:input-value="input.val"
None of these affect the starting state of the checkbox though. If input.val
starts off as 1
, why does this box not start off checked?
<v-checkbox
v-else-if="input.type == 'checkbox'"
false-value="0"
true-value="1"
:value="input.val"
:input-value="input.val"
v-model="input.val"
:error-messages="form.errors[field]"
>
<template #label>@{{ input.hint }}</template>
</v-checkbox>
I have a Vue JS app that uses a Vuetify checkbox. I am unable to set the initial value to checked.
<v-checkbox
v-else-if="input.type == 'checkbox'"
false-value="0"
true-value="1"
v-model="input.val"
:error-messages="form.errors[field]"
>
When input.val
is equal to 1
i expect the checkbox to start off checked. However the checkbox will not start off checked.
I have also tried adding the props:
:value="input.val"
:input-value="input.val"
None of these affect the starting state of the checkbox though. If input.val
starts off as 1
, why does this box not start off checked?
<v-checkbox
v-else-if="input.type == 'checkbox'"
false-value="0"
true-value="1"
:value="input.val"
:input-value="input.val"
v-model="input.val"
:error-messages="form.errors[field]"
>
<template #label>@{{ input.hint }}</template>
</v-checkbox>
Share
Improve this question
edited Apr 28, 2023 at 16:39
Moritz Ringler
16.1k10 gold badges27 silver badges45 bronze badges
asked Jul 7, 2019 at 0:50
VerySeriousSoftwareEndeavoursVerySeriousSoftwareEndeavours
1,7534 gold badges33 silver badges64 bronze badges
2 Answers
Reset to default 6You need to use :
or v-bind
for numbers, if you use v-bind:true-value
it`s work fine. Example on codepen.
Example
<div id="app">
<v-app id="inspire">
<v-container fluid>
<v-checkbox v-model="checkbox1"
v-bind:false-value="0"
v-bind:true-value="1"
:label="`Checkbox 1: ${checkbox1.toString()}`"></v-checkbox>
<v-checkbox v-model="checkbox2" :label="`Checkbox 2: ${checkbox2.toString()}`"></v-checkbox>
</v-container>
</v-app>
</div>
new Vue({
el: '#app',
data () {
return {
checkbox1: 1,
checkbox2: 0
}
}
})
Try removing the false-value
and true-value
, and using false
or true
telling it if it should be checked in value
.