This document outlines the integration of the @lambdacurry/forms library into the React Router 7 starter project.
@lambdacurry/forms- The main forms library@hookform/resolvers- Zod resolver for React Hook Formreact-hook-form- Form state managementremix-hook-form- React Router integrationzod- Schema validation
- Added
ai-rules/lambda-curry-forms.mdwith comprehensive guidelines for using the forms library - Generated outputs in
ai-rules/.generated-ai-rules/and.cursor/rules/are managed by repository automation; update source rules instead of editing generated files directly.
Before: Basic React state with manual form handling
const [text, setText] = useState('');
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (text.trim()) {
onAdd(text.trim());
setText('');
}
};After: Lambda Curry forms with Zod validation
const addTodoSchema = z.object({
text: z.string().min(1, 'Todo text is required').trim(),
});
const methods = useRemixForm<AddTodoFormData>({
resolver: zodResolver(addTodoSchema),
defaultValues: { text: '' },
submitHandlers: {
onValid: (data) => {
onAdd(data.text);
methods.reset();
},
},
});Enhanced editing functionality:
- Replaced manual input handling with
TextFieldcomponent - Added Zod validation for edit operations
- Integrated
FormErrorcomponent for error display - Maintained keyboard shortcuts (Enter to save, Escape to cancel)
A comprehensive form demonstrating all major features:
Form Fields:
- Title - Required text field with length validation
- Description - Optional multiline text field
- Priority - RadioGroup with low/medium/high options
- Category - Required text field
- Due Date - Optional DatePicker
- Tags - Optional text field
- Is Urgent - Checkbox for boolean flag
Features Demonstrated:
- ✅ Server-side validation with
getValidatedFormData - ✅ Client-side validation with Zod schemas
- ✅ Form-level error handling with
FormError - ✅ Progressive enhancement (works without JS)
- ✅ Type-safe form data with TypeScript
- ✅ Accessibility compliance (WCAG 2.1 AA)
- ✅ Loading states and success feedback
type CreateTodoFormData = z.infer<typeof createTodoSchema>;
// Automatic TypeScript types from Zod schemaconst createTodoSchema = z.object({
title: z.string().min(1, 'Title is required').max(100, 'Title must be less than 100 characters'),
priority: z.enum(['low', 'medium', 'high'], {
required_error: 'Please select a priority level',
}),
});export const action = async ({ request }: ActionFunctionArgs) => {
const { data, errors } = await getValidatedFormData<CreateTodoFormData>(
request,
zodResolver(createTodoSchema)
);
if (errors) return { errors };
// Process valid data...
};// Form-level errors
<FormError />
// Field-level errors (automatic)
<TextField name="title" label="Title" />- Navigate to the home page
- Use the "Add Todo" form (now powered by Lambda Curry forms)
- Try submitting empty text to see validation
- Create a todo and click the edit button
- Try clearing the text and saving to see validation
- Use Enter/Escape keys for save/cancel
- Click "Advanced Todo Form" button
- Fill out the comprehensive form
- Try various validation scenarios:
- Submit without required fields
- Enter "error" in title to trigger server error
- Test all form components
<TextField
name="fieldName"
label="Field Label"
placeholder="Enter text..."
required
/><RadioGroup
name="priority"
label="Priority Level"
options={[
{ value: 'low', label: 'Low Priority' },
{ value: 'medium', label: 'Medium Priority' },
{ value: 'high', label: 'High Priority' },
]}
/><Checkbox
name="isUrgent"
label="Mark as urgent"
/><DatePicker
name="dueDate"
label="Due Date (Optional)"
/>- Define Schema: Create Zod schema for validation
- Setup Form: Use
useRemixFormwith resolver - Add Components: Use Lambda Curry form components
- Handle Submission: Implement server action with
getValidatedFormData - Error Handling: Add
FormErrorcomponent for form-level errors
The forms library integrates seamlessly with:
- Tailwind CSS - All components are styled with Tailwind
- shadcn/ui - Compatible with existing design system
- Dark Mode - Supports theme switching
- Responsive Design - Mobile-first approach
- Install Dependencies: Run
bun installto install new packages - Run Development: Use
bun run devto start the development server - Explore Examples: Navigate through the updated components and new route
- Read AI Rules: Review
ai-rules/lambda-curry-forms.mdfor detailed guidelines
This integration provides a solid foundation for building type-safe, accessible, and maintainable forms in React Router 7 applications using the Lambda Curry forms library.