Specifying true/false values for a Vuetify v-checkbox

12,133

You should use v-model directive instead of input-value prop like :

<v-checkbox
     v-else-if="input.type == 'checkbox'"
     false-value="0"
      true-value="1"
     v-model="input.val"
    :error-messages="form.errors[field]"
                            >
    <template #label>@{{ input.hint }}</template>
</v-checkbox>

check this code example

Share:
12,133
VerySeriousSoftwareEndeavours
Author by

VerySeriousSoftwareEndeavours

I am a Senior LAMP(Linux/Apache/MySQL/PHP) Engineer with more than 15 years of experience in full stack software development. I have been building large scale applications in the MVC/ORM design patterns for over 10 years. I specialize in development of Server Side PHP applications as well as reactive data-driven Javascript SPA's. I develop secure &amp; efficient enterprise scale commercial SaaS web applications, utilizing rapid application MVC frameworks. Laravel / Vue JS / Vuetify are my current favorite set of choices for the bases of my web applications.

Updated on August 03, 2022

Comments

  • VerySeriousSoftwareEndeavours
    VerySeriousSoftwareEndeavours over 1 year

    I am using the Vuetify component v-checkbox.

    I want to specify specific values for the true/false states of the checkbox.

    Looking at the documentation it looks like I can do this using the true-value & false-value props.

    <v-checkbox
        v-else-if="input.type == 'checkbox'"
        false-value="0"
        true-value="1"
        input-value="input.val"
        :error-messages="form.errors[field]"
    >
        <template #label>@{{ input.hint }}</template>
    </v-checkbox>
    

    However using the example above does not submit a value of 1 when the checkbox is checked. The checkbox submits 0 regardless of whether the checkbox is checked or not.

    What do I need to do to properly set the true-value to 1?

  • VerySeriousSoftwareEndeavours
    VerySeriousSoftwareEndeavours almost 5 years
    After I made this change I am not able to set the initial value of the checkbox anymore. I expect that if "input.val" is '1', then the checkbox would start off checked. Why does 'input.val' not check the box?
  • VerySeriousSoftwareEndeavours
    VerySeriousSoftwareEndeavours almost 5 years
    Yes. This fixes the true/false values of the checkbox. i.e. It submits 1 when checked, 0 when unchecked. However this only works when the box starts off unchecked. If 'input.val' is already equal to '1' when the component renders it does not start the checkbox off checked...