Specifying true/false values for a Vuetify v-checkbox
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
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 & 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, 2022Comments
-
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 submits0
regardless of whether the checkbox is checked or not.What do I need to do to properly set the
true-value
to1
? -
VerySeriousSoftwareEndeavours almost 5 yearsAfter 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 almost 5 yearsYes. 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...