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>
You 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
}
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With