Closed kikky7 closed 1 month ago
I used this with the checkbox component, but I find it ugly solution, and would be great to support multicheck via v-model directly:
<Checkbox
:id="`tag-${key}`"
:value="key"
:checked="form.tags.includes(key)"
@update:checked="(isChecked) => isChecked ? form.tags.push(key) : form.tags.splice(form.tags.indexOf(key), 1)" />
The radix-vue
checkbox already has the same props
and emits
, whether you want to use vee-validate
or inertiajs
useForm it should work with booleans and arrays
It may be better to create a minimal reproduction
I see there is an example using Form (vee-validate)
This example in shadcn-vue
might help you, Checkbox
with array, even if you don't want to use vee-validate
Closing for now will reopen after reproduction
There is no need for reproduction, this <Checkbox id="tags" v-model:checked="form.tags" />
should work with booleans and arrays, but it's not as I represented with my custom component, but it works only with boolean.
Only way to make it work with array is this code, which is just dirty looking:
<Checkbox
:id="`tag-${key}`"
:value="key"
:checked="form.tags.includes(key)"
@update:checked="(isChecked) => isChecked ? form.tags.push(key) : form.tags.splice(form.tags.indexOf(key), 1)" />
If you want I can create PR to implement such behaviour into your current component, using radix-vue
Make a Vue Playground with Stackblitz please, see if we could help
With reproduction, we can check it ourselves to see if it is really a bug or not
https://stackblitz.com/edit/inertia-sails-vue-nkt3qm?file=package.json
Just fork this link and delete additional files and make it minimal and send it here
Reproduction
I don't think it's required.
Describe the bug
This works because form.remember is boolean:
<Checkbox id="remember" v-model:checked="form.remember" />
This is not working and I tried 10 different combinations (form.tags is an empty array), and tags is simple key:value object:
I tried
v-model="form.tags"
and some other (desperate) solutions, none worked. I see there is an example using Form (vee-validate); I don't want to use this if I don't have too.I am using Inertia.js useForm.
So I ended up creating my own checkbox component, just to see if it works, and it does (with the same code above), which works with booleans and arrays:
So it's bug somewhere with
radix-vue
probably, or if it's not, how to achieve this?System Info
Contributes