DynamicForm
DynamicForm compiles a declarative 2D matrix of field configurations (rows: FieldConfig[][]) into a fully validated React Hook Form. It dynamically generates an exact Zod validation schema from field rules (required, min, max, regex, file constraints), auto-populates initial values, and manages submission lifecycles with built-in or custom submit footers.
Props & Configuration
11 propsComplete property specifications, parameter types, and default fallbacks.
| Property | Type | Default | Description |
|---|---|---|---|
| schema | FormSchema | — | Form layout configuration containing rows: FieldConfig[][]. Optional if apiUrl is provided. |
| apiUrl | string | — | Remote endpoint to fetch form schema dynamically from the server. |
| method | "GET" | "POST" | "GET" | HTTP method used when querying apiUrl. |
| initialValues | Record<string, any> | — | Default values to populate or override schema defaults. |
| onSubmitRequired | (data: any) => void | Promise<void> | — | Callback invoked with validated form data upon successful submission. |
| onError | (errors: Record<string, any>) => void | — | Callback triggered when form validation fails. |
| submitText | string | "Submit" | Label displayed on the primary submit button. |
| isSubmitting | boolean | false | Toggles loading spinner state on the submit button. |
| showSubmitButton | boolean | true | Whether to render the default submit button. |
| className | string | "w-full p-4 flex flex-col gap-4" | Custom class for the form wrapper container. |
| renderFooter | (methods: UseFormReturn<any>) => React.ReactNode | — | Custom footer slot allowing complete control over buttons, cancel links, and reset actions. |
Interactive Examples & Live Previews
3 DemosEvery example includes its own live, interactive preview element alongside the corresponding copyable TypeScript snippet.
Basic Two-Column Registration Form
Standard two-column form with automatic Zod validation and submit callback.
1import React from "react";2import { DynamicForm, FormSchema } from "antd-dynamic-ui";3import { message } from "antd";45const registrationSchema: FormSchema = {6 rows: [7 [8 {9 id: "fullName",10 type: "text",11 label: "Full Name",12 placeholder: "e.g. Sarah Connor",13 required: true,14 span: 12,15 tooltip: "Your legal full name as shown on passport",16 },17 {18 id: "email",19 type: "email",20 label: "Email Address",21 placeholder: "sarah@skynet.com",22 required: true,23 span: 12,24 validation: { required: true, pattern: "^\\S+@\\S+\\.\\S+$" },25 },26 ],27 [28 {29 id: "accountType",30 type: "select",31 label: "Account Plan",32 defaultValue: "pro",33 options: [34 { key: "free", value: "Starter Plan (Free)" },35 { key: "pro", value: "Professional ($29/mo)" },36 { key: "enterprise", value: "Enterprise (Custom)" },37 ],38 span: 24,39 },40 ],41 ],42};4344export default function QuickRegisterForm() {45 const handleSubmit = async (formData: any) => {46 message.loading({ content: "Registering account...", key: "reg" });47 await new Promise((resolve) => setTimeout(resolve, 800));48 message.success({ content: `Welcome, ${formData.fullName}!`, key: "reg" });49 };5051 return (52 <div className="max-w-2xl mx-auto p-6 bg-white rounded-2xl shadow-sm border border-[#ede5d8]">53 <h2 className="text-xl font-bold mb-4">Create Your Account</h2>54 <DynamicForm55 schema={registrationSchema}56 onSubmit={handleSubmit}57 submitText="Create Account"58 />59 </div>60 );61}
Complete Props, Conditional Logic & Custom Footer
Enterprise checkout form with conditional fields, custom footer, initial values, and error listeners.
1import React, { useState } from "react";2import { DynamicForm, FormSchema, ButtonField } from "antd-dynamic-ui";3import { Alert, message } from "antd";45const enterpriseSchema: FormSchema = {6 rows: [7 [8 {9 id: "organization",10 type: "text",11 label: "Company / Organization",12 required: true,13 span: 12,14 },15 {16 id: "hasVatNumber",17 type: "toggle",18 label: "Do you have an EU VAT Number?",19 defaultValue: false,20 span: 12,21 },22 ],23 // Conditional row: Only appears if hasVatNumber === true24 [25 {26 id: "vatId",27 type: "text",28 label: "EU VAT ID",29 placeholder: "e.g. DE123456789",30 span: 24,31 conditions: [32 { field: "hasVatNumber", operator: "equals", value: true },33 ],34 validation: { minLength: 8, maxLength: 14 },35 },36 ],37 [38 {39 id: "securityClearance",40 type: "slider",41 label: "Minimum Team Size Required",42 defaultValue: 25,43 span: 12,44 },45 {46 id: "primaryCountry",47 type: "country",48 label: "Headquarters Region",49 defaultValue: "DE",50 span: 12,51 },52 ],53 ],54};5556export default function AdvancedOrganizationForm() {57 const [isSubmitting, setIsSubmitting] = useState(false);58 const [lastError, setLastError] = useState<string | null>(null);5960 const onSubmit = async (values: any) => {61 setIsSubmitting(true);62 setLastError(null);63 try {64 console.log("Validated Payload:", values);65 message.success("Organization profile saved!");66 } catch (err: any) {67 setLastError(err.message);68 } finally {69 setIsSubmitting(false);70 }71 };7273 return (74 <div className="space-y-4 max-w-3xl mx-auto p-6 bg-white border border-[#ede5d8] rounded-2xl shadow-sm">75 {lastError && <Alert type="error" message={lastError} showIcon />}7677 <DynamicForm78 schema={enterpriseSchema}79 initialValues={{ organization: "DeepMind Tech Ltd" }}80 onSubmit={onSubmit}81 onError={(errors) => console.warn("Validation Errors:", errors)}82 isSubmitting={isSubmitting}83 showSubmitButton={false} // Using custom footer instead84 renderFooter={(methods) => (85 <div className="flex items-center justify-between pt-4 border-t border-[#ede5d8]">86 <button87 type="button"88 onClick={() => methods.reset()}89 className="px-4 py-2 text-xs font-semibold text-zinc-600 hover:text-zinc-900"90 >91 Reset to Defaults92 </button>93 <div className="flex gap-2">94 <ButtonField95 type="default"96 onClick={() => console.log("Draft:", methods.getValues())}97 >98 Save as Draft99 </ButtonField>100 <ButtonField101 type="primary"102 loading={isSubmitting}103 onClick={methods.handleSubmit(onSubmit)}104 >105 Publish Organization106 </ButtonField>107 </div>108 </div>109 )}110 />111 </div>112 );113}
Remote Schema from API Endpoint
Loading form structure dynamically from a microservice endpoint with zero client schema code.
1import React from "react";2import { DynamicForm } from "antd-dynamic-ui";3import { message } from "antd";45export default function MicroserviceDynamicForm() {6 return (7 <div className="p-6">8 <h3 className="text-lg font-bold mb-3">Dynamically Injected Form</h3>9 <DynamicForm10 apiUrl="/api/v1/schemas/vendor-onboarding"11 method="GET"12 onSubmit={async (data) => {13 message.success("Vendor submitted successfully!");14 console.log("Payload:", data);15 }}16 submitText="Complete Onboarding"17 />18 </div>19 );20}
Expected Backend API Response Schema
Ensure your backend endpoint returns JSON matching this exact structure to prevent hydration and rendering errors.
Expected API Response Payload
Your backend API must return JSON matching this exact structure.
{
"rows": [
[
{
"id": "username",
"type": "text",
"label": "Username",
"required": true,
"span": 12
},
{
"id": "role",
"type": "select",
"label": "Role",
"options": [
{
"key": "admin",
"value": "Admin"
}
],
"span": 12
}
]
]
}Frequently Asked Questions & Quick Solutions
Architectural patterns, React 19 compatibility, and integration tips for DynamicForm.
How does DynamicForm integrate with Ant Design 5.x and Next.js 15?▼
DynamicForm is designed as an enhanced, declarative wrapper for Ant Design. It fully supports Next.js 15 App Router when using @ant-design/nextjs-registry, eliminating SSR hydration mismatches and guaranteeing 0ms layout thrashing.
Can I customize validation, themes, and props for DynamicForm?▼
Yes. Every prop is fully typed in TypeScript 5 with comprehensive Intellisense. You can pass custom styling via className or style props, configure global Ant Design themes via ConfigProvider, and extend validation logic seamlessly.