Form (RHF Integration)
A set of components that bridge React Hook Form with accessible form markup. Provides context for field-level error display and label association.
Import
import {
Form, FormField, FormItem, FormLabel,
FormControl, FormDescription, FormMessage,
} from "@phpcreation/frontend-components-react-nextjs-bundle/components/Form";Component Roles
| Component | Role |
|---|---|
Form | Wraps FormProvider — passes RHF context |
FormField | Wraps Controller — connects a field to RHF |
FormItem | Wrapper div with spacing |
FormLabel | Accessible label linked to the field |
FormControl | Wraps the input — connects aria-describedby |
FormDescription | Helper text below the input |
FormMessage | Validation error message |
Usage
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import {
Form, FormField, FormItem, FormLabel,
FormControl, FormMessage,
} from "...";
import { Input } from "...";
import { Button } from "...";
const schema = z.object({
name: z.string().min(2, "Name must be at least 2 characters"),
});
export function ProfileForm() {
const form = useForm({ resolver: zodResolver(schema) });
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(console.log)}>
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit">Save</Button>
</form>
</Form>
);
}In CRUD forms, these components are used internally by RenderFormFields. You typically won’t compose them manually unless building custom form layouts.
Related
- Input — uses FormLabel internally
- Render Form Fields
- Add Entity
Last updated on