Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Typography
Get Started
@shadcn/react
@shadcn/helpers
Force UI registry
Utilities
Installation#
pnpm dlx shadcn@latest add @force-ui-vue/form
Usage#
<script setup lang="ts">
import {
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"
</script>
<template>
<FormField v-slot="{ componentField }" name="username">
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Input placeholder="shadcn" v-bind="componentField" />
</FormControl>
<FormDescription> This is your public display name. </FormDescription>
<FormMessage />
</FormItem>
</FormField>
</template>Create a form schema#
Define the shape of your form using a Zod schema. You can read more about using Zod in the Zod documentation.
Use @vee-validate/zod to integrate Zod schema validation with vee-validate
toTypedSchema also makes the form values and submitted values typed automatically and caters for both input and output types of that schema.
<script setup lang="ts">
import { toTypedSchema } from "@vee-validate/zod"
import * as z from "zod"
const formSchema = toTypedSchema(
z.object({
username: z.string().min(2).max(50),
})
)
</script>Define a form#
Use the useForm composable from vee-validate or use <Form /> component to create a form.
<script setup lang="ts">
import { toTypedSchema } from "@vee-validate/zod"
import { useForm } from "vee-validate"
import * as z from "zod"
import {
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"
const formSchema = toTypedSchema(
z.object({
username: z.string().min(2).max(50),
})
)
const form = useForm({
validationSchema: formSchema,
})
const onSubmit = form.handleSubmit((values) => {
console.log("Form submitted!", values)
})
</script>
<template>
<form @submit="onSubmit">...</form>
</template>
``` ```vue showLineNumbers {5,24-26}
<script setup lang="ts">
import { toTypedSchema } from "@vee-validate/zod"
import * as z from "zod"
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"
const formSchema = toTypedSchema(
z.object({
username: z.string().min(2).max(50),
})
)
function onSubmit(values) {
console.log("Form submitted!", values)
}
</script>
<template>
<Form :validation-schema="formSchema" @submit="onSubmit"> ... </Form>
</template>
``` ### Build your form Based on last step we can either use `
<Form />
` component or `useForm` composable `useForm` is recommended because values are
typed automatically ```vue showLineNumbers {2}
<script setup lang="ts">
import { toTypedSchema } from "@vee-validate/zod"
import { useForm } from "vee-validate"
import * as z from "zod"
import { Button } from "@/components/ui/button"
import {
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"
import { Input } from "@/components/ui/input"
const formSchema = toTypedSchema(
z.object({
username: z.string().min(2).max(50),
})
)
const form = useForm({
validationSchema: formSchema,
})
const onSubmit = form.handleSubmit((values) => {
console.log("Form submitted!", values)
})
</script>
<template>
<form @submit="onSubmit">
<FormField v-slot="{ componentField }" name="username">
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Input type="text" placeholder="shadcn" v-bind="componentField" />
</FormControl>
<FormDescription> This is your public display name. </FormDescription>
<FormMessage />
</FormItem>
</FormField>
<Button type="submit"> Submit </Button>
</form>
</template>Done#
That's it. You now have a fully accessible form that is type-safe with client-side validation.
Deploy your shadcn/ui app on Vercel
Trusted by OpenAI, Sonos, Adobe, and more.
Vercel provides tools and infrastructure to deploy apps and features at scale.
Deploy to Vercel