2
votes

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>
2

2 Answers

3
votes

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
    }
  }
})
0
votes

Try removing the false-value and true-value, and using false or true telling it if it should be checked in value.