1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
---
description: Set up a form with React Hook Form and Zod validation
argument-hint: <form-name>
allowed-tools: Read, Write, Edit, Bash
---
Create a complete form setup with React Hook Form, Zod validation, and shadcn/ui form components.
## Instructions
1. Install required dependencies if not present:
- `react-hook-form`
- `@hookform/resolvers`
- `zod`
- Required shadcn components: `form`, `input`, `button`, etc.
2. Create the form with:
- Zod schema for validation
- Form component with React Hook Form
- Proper error handling
- Loading states
- Success feedback
## Template Structure
```tsx
// lib/validations/[form-name].ts
import * as z from "zod"
export const [formName]Schema = z.object({
// Define fields
})
export type [FormName]Values = z.infer<typeof [formName]Schema>
// components/forms/[form-name]-form.tsx
import { useForm } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { [formName]Schema, type [FormName]Values } from "@/lib/validations/[form-name]"
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Button } from "@/components/ui/button"
import { toast } from "@/components/ui/use-toast"
export function [FormName]Form() {
const form = useForm<[FormName]Values>({
resolver: zodResolver([formName]Schema),
defaultValues: {
// Set defaults
},
})
async function onSubmit(data: [FormName]Values) {
try {
// Handle submission
toast({
title: "Success",
description: "Form submitted successfully",
})
} catch (error) {
toast({
title: "Error",
description: "Something went wrong",
variant: "destructive",
})
}
}
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
{/* Form fields */}
<Button
type="submit"
disabled={form.formState.isSubmitting}
>
{form.formState.isSubmitting ? "Submitting..." : "Submit"}
</Button>
</form>
</Form>
)
}
```
## Common Form Types
- **contact-form**: Name, email, message
- **login-form**: Email/username, password
- **register-form**: Name, email, password, confirm password
- **profile-form**: Avatar, bio, social links
- **settings-form**: Preferences, notifications
- **checkout-form**: Billing, shipping, payment
## Field Types to Consider
- Text inputs (email, url, tel, password)
- Textareas for long text
- Select dropdowns
- Radio groups
- Checkboxes
- Date pickers
- File uploads
- Number inputs with validation
## Example
If the user says: `/setup-form contact`
1. Install dependencies:
```bash
npm install react-hook-form @hookform/resolvers zod
npx shadcn@latest add form input textarea button
```
2. Create validation schema
3. Create form component with name, email, message fields
4. Add proper validation rules
5. Include submit handler with loading state
|