Skip to content

Commit

Permalink
docs: fix vee-validate checkbox and radio-group examples (#213)
Browse files Browse the repository at this point in the history
* docs: fix checkbox and radio form examples

add type="checkbox|radio" and name in FormField

* docs: add `vee-validate` documentation link for checkbox and radio inputs

* chore: update `vee-validate` deps
  • Loading branch information
sadeghbarati authored Dec 19, 2023
1 parent 96da2d8 commit b40321e
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 38 deletions.
4 changes: 2 additions & 2 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@tanstack/vue-table": "^8.10.7",
"@unovis/ts": "^1.2.3",
"@unovis/vue": "1.3.0-beta.3",
"@vee-validate/zod": "^4.11.8",
"@vee-validate/zod": "^4.12.3",
"@vueuse/core": "^10.5.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
Expand All @@ -31,7 +31,7 @@
"radix-vue": "^1.2.3",
"tailwindcss-animate": "^1.0.7",
"v-calendar": "^3.1.2",
"vee-validate": "4.11.8",
"vee-validate": "4.12.3",
"vue": "^3.3.7",
"vue-wrap-balancer": "^1.1.3",
"zod": "^3.22.4"
Expand Down
2 changes: 2 additions & 0 deletions apps/www/src/content/docs/components/checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { Checkbox } from '@/components/ui/checkbox'

### Form

Please first read `vee-validate` section for [Checkbox and Radio Inputs](https://vee-validate.logaretm.com/v4/examples/checkboxes-and-radio/)

<ComponentPreview name="CheckboxFormSingle" />

<ComponentPreview name="CheckboxFormMultiple" />
2 changes: 2 additions & 0 deletions apps/www/src/content/docs/components/radio-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'

### Form

Please first read `vee-validate` section for [Checkbox and Radio Inputs](https://vee-validate.logaretm.com/v4/examples/checkboxes-and-radio/)

<ComponentPreview name="RadioGroupForm" />
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,12 @@ const onSubmit = handleSubmit((values) => {
</FormDescription>
</div>

<FormField v-for="item in items" v-slot="{ value, handleChange }" :key="item.id" name="items">
<FormItem :key="item.id" class="flex flex-row items-start space-x-3 space-y-0">
<FormField v-for="item in items" v-slot="{ value, handleChange }" :key="item.id" type="checkbox" :value="item.id" :unchecked-value="false" name="items">
<FormItem class="flex flex-row items-start space-x-3 space-y-0">
<FormControl>
<Checkbox
:checked="value.includes(item.id)"
@update:checked="(checked) => {
if (Array.isArray(value)) {
handleChange(checked ? [...value, item.id] : value.filter(id => id !== item.id))
}
}"
@update:checked="handleChange"
/>
</FormControl>
<FormLabel class="font-normal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const onSubmit = handleSubmit((values) => {

<template>
<form class="space-y-6" @submit="onSubmit">
<FormField v-slot="{ value, handleChange }" name="mobile">
<FormField v-slot="{ value, handleChange }" type="checkbox" name="mobile">
<FormItem class="flex flex-row items-start gap-x-3 space-y-0 rounded-md border p-4">
<FormControl>
<Checkbox :checked="value" @update:checked="handleChange" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const onSubmit = handleSubmit((values) => {

<template>
<form class="w-2/3 space-y-6" @submit="onSubmit">
<FormField v-slot="{ componentField }" name="type">
<FormField v-slot="{ componentField }" type="radio" name="type">
<FormItem class="space-y-3">
<FormLabel>Notify me about...</FormLabel>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,12 @@ const onSubmit = handleSubmit((values) => {
</FormDescription>
</div>

<FormField v-for="item in items" v-slot="{ value, handleChange }" :key="item.id" name="items">
<FormItem :key="item.id" class="flex flex-row items-start space-x-3 space-y-0">
<FormField v-for="item in items" v-slot="{ value, handleChange }" :key="item.id" type="checkbox" :value="item.id" :unchecked-value="false" name="items">
<FormItem class="flex flex-row items-start space-x-3 space-y-0">
<FormControl>
<Checkbox
:checked="value.includes(item.id)"
@update:checked="(checked) => {
if (Array.isArray(value)) {
handleChange(checked ? [...value, item.id] : value.filter(id => id !== item.id))
}
}"
@update:checked="handleChange"
/>
</FormControl>
<FormLabel class="font-normal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const onSubmit = handleSubmit((values) => {

<template>
<form class="space-y-6" @submit="onSubmit">
<FormField v-slot="{ value, handleChange }" name="mobile">
<FormField v-slot="{ value, handleChange }" type="checkbox" name="mobile">
<FormItem class="flex flex-row items-start gap-x-3 space-y-0 rounded-md border p-4 shadow">
<FormControl>
<Checkbox :checked="value" @update:checked="handleChange" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const onSubmit = handleSubmit((values) => {

<template>
<form class="w-2/3 space-y-6" @submit="onSubmit">
<FormField v-slot="{ componentField }" name="type">
<FormField v-slot="{ componentField }" type="radio" name="type">
<FormItem class="space-y-3">
<FormLabel>Notify me about...</FormLabel>

Expand Down
36 changes: 18 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b40321e

Please sign in to comment.