Skip to Content

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

  1. Entity config provides the field definitions and Zod schema
  2. useDefaultFormValues populates initial empty values
  3. RenderFormFields renders the form
  4. On submit, validateFormSchema validates, then API POST is made
  5. 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

PropTypeDescription
entityConfigEntityConfigEntity configuration
formFieldsFieldConfig[]Fields to render
schemaZodSchemaValidation schema
onSuccess(entity: Entity) => voidOptional success callback
defaultValuesPartial<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.


Last updated on