Add Entity
The Add Entity page renders a full form for creating a new entity. It uses RenderFormFields to render fields, validates with Zod, and POSTs to the API on submit.
Import
import { AddEntity } from "@phpcreation/frontend-crud-react-nextjs-bundle/components/AddEntity";How It Works
- Entity config provides the field definitions and Zod schema
useDefaultFormValuespopulates initial empty valuesRenderFormFieldsrenders the form- On submit,
validateFormSchemavalidates, then API POST is made - On success, redirects to the listing or detail page
Usage
// app/[locale]/entities/add/page.tsx (generated)
import { AddEntity } from "...";
import { entityConfig, entityFormFields, entitySchema } from "../entity.config";
export default function AddEntityPage() {
return (
<AddEntity
entityConfig={entityConfig}
formFields={entityFormFields}
schema={entitySchema}
/>
);
}Props
| Prop | Type | Description |
|---|---|---|
entityConfig | EntityConfig | Entity configuration |
formFields | FieldConfig[] | Fields to render |
schema | ZodSchema | Validation schema |
onSuccess | (entity: Entity) => void | Optional success callback |
defaultValues | Partial<Entity> | Pre-populate field values |
Custom Properties
If the entity supports custom properties, CustomPropertiesFormSection is rendered automatically at the bottom of the form. See Custom Properties.
The generator creates Add Entity pages automatically. You typically only customize the defaultValues or add form section wrappers.
Related
Last updated on