React Forms

Each form on this page is a live @schema-engine/forms-react form. The code block under it is serialized from the same object the form renders, so the two cannot drift. Submit handling is local: a valid submit shows the submitted values under the form and nothing reaches a server.

Most examples use the docs' Radiant-styled demo kit, so they share their configuration with the Radiant examples (Basic form, Contact form, Registration flow, Survey form, Sequential actions). The last section uses source copied from the shadcn registry.

Basic form

A single step on the card recipe. Submit it empty to see the required-field errors.

Your Information

Get in touch with our team

const basicContactFormConfig: FormConfig = {
	id: 'basic-contact',
	title: 'Contact Us',
	description: 'Get in touch with our team',
	steps: [
		{
			id: 'details',
			title: 'Your Information',
			elements: [
				{
					$type: 'input',
					id: 'name',
					name: 'name',
					label: 'Full Name',
					inputType: 'text',
					rules: [
						{
							type: 'required',
							message: 'Name is required'
						}
					]
				},
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email Address',
					inputType: 'email',
					rules: [
						{
							type: 'required',
							message: 'Email is required'
						},
						{
							type: 'email',
							message: 'Invalid email format'
						}
					]
				},
				{
					$type: 'textarea',
					id: 'message',
					name: 'message',
					label: 'Message',
					rows: 5
				}
			]
		}
	],
	view: {
		$type: 'card',
		shell: {
			appearance: {
				size: 'default',
				surface: 'elevated'
			}
		}
	}
};

Validation

Rules sit on the element and run on submit. An invalid submit shows each message beside its field, keeps what you typed, and does not reload the page or put values in the URL. See Validation for every rule.

Join the beta

Submit it empty, then fix one field at a time.

const validationDemoConfig: FormConfig = {
	id: 'validation-demo',
	title: 'Join the beta',
	description: 'Submit it empty, then fix one field at a time.',
	view: {
		$type: 'card',
		shell: {
			appearance: {
				size: 'default',
				surface: 'elevated'
			}
		},
		header: {
			align: 'center',
			size: 'md'
		}
	},
	steps: [
		{
			id: 'details',
			title: 'Join the beta',
			elements: [
				{
					$type: 'input',
					id: 'name',
					name: 'name',
					label: 'Name',
					rules: [
						{
							type: 'required',
							message: 'Name is required'
						},
						{
							type: 'minLength',
							value: 2,
							message: 'Use at least 2 characters'
						}
					]
				},
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email',
					inputType: 'email',
					rules: [
						{
							type: 'required',
							message: 'Email is required'
						},
						{
							type: 'email',
							message: 'Enter a valid email'
						}
					]
				},
				{
					$type: 'input',
					id: 'website',
					name: 'website',
					label: 'Website',
					inputType: 'url',
					rules: [
						{
							type: 'required',
							message: 'Website is required'
						},
						{
							type: 'url',
							message: 'Enter a full URL, such as https://example.com'
						}
					]
				},
				{
					$type: 'input',
					id: 'postcode',
					name: 'postcode',
					label: 'Postcode',
					rules: [
						{
							type: 'required',
							message: 'Postcode is required'
						},
						{
							type: 'pattern',
							value: '^[0-9]{5}$',
							message: 'Use five digits'
						}
					]
				}
			]
		}
	]
};

Conditional fields

Choose "Technical support" and the ticket field appears, with its own required rule. See constraint logic.

Contact us

Send a message with conditional fields.

const contactFormDemoConfig: FormConfig = {
	id: 'contact',
	title: 'Contact us',
	description: 'Send a message with conditional fields.',
	steps: [
		{
			id: 'details',
			title: 'Contact us',
			elements: [
				{
					$type: 'select',
					id: 'subject',
					name: 'subject',
					label: 'Subject',
					options: [
						{
							value: 'general',
							label: 'General question'
						},
						{
							value: 'support',
							label: 'Technical support'
						}
					],
					rules: [
						{
							type: 'required',
							message: 'Subject is required'
						}
					]
				},
				{
					$type: 'input',
					id: 'ticket',
					name: 'ticket',
					label: 'Support ticket number',
					constraints: [
						{
							field: 'subject',
							operator: 'equals',
							value: 'support',
							action: 'show'
						}
					],
					rules: [
						{
							type: 'required',
							message: 'Support ticket number is required'
						}
					]
				},
				{
					$type: 'textarea',
					id: 'message',
					name: 'message',
					label: 'Message',
					rules: [
						{
							type: 'required',
							message: 'Message is required'
						}
					]
				}
			]
		}
	],
	view: {
		$type: 'card',
		shell: {
			appearance: {
				size: 'default',
				surface: 'elevated'
			}
		},
		header: {
			align: 'center',
			size: 'md'
		}
	}
};

Layout

Placement is data too: a field's grid puts two fields on one row, and the form's appearance sizes the card. The styling recipes render the same contact card live in React and in Radiant, with its CSS.

Multi-step wizard

The wizard recipe owns progress and navigation. Fill the first step and select Next: the second step opens, and Previous returns to the first with its values kept. See View recipes.

Account

const viewRecipesDemoConfig: FormConfig = {
	id: 'onboarding',
	title: 'Create your account',
	view: {
		$type: 'wizard'
	},
	steps: [
		{
			id: 'account',
			title: 'Account',
			elements: [
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email Address',
					inputType: 'email',
					rules: [
						{
							type: 'required',
							message: 'Email is required'
						}
					]
				},
				{
					$type: 'input',
					id: 'password',
					name: 'password',
					label: 'Password',
					inputType: 'password',
					rules: [
						{
							type: 'required',
							message: 'Password is required'
						},
						{
							type: 'minLength',
							value: 8,
							message: 'Use at least 8 characters'
						}
					]
				}
			]
		},
		{
			id: 'profile',
			title: 'Profile',
			elements: [
				{
					$type: 'select',
					id: 'role',
					name: 'role',
					label: 'Role',
					placeholder: 'Select your role',
					rules: [
						{
							type: 'required',
							message: 'Role is required'
						}
					],
					options: [
						{
							value: 'developer',
							label: 'Developer'
						},
						{
							value: 'designer',
							label: 'Designer'
						},
						{
							value: 'product',
							label: 'Product Manager'
						}
					]
				},
				{
					$type: 'checkbox',
					id: 'newsletter',
					name: 'newsletter',
					label: 'Newsletter',
					description: 'Optional. Send me product updates.'
				}
			]
		}
	]
};

Submission and actions

The submit request runs on form_submit; a notification and a reset then run on form_submit_success, so the fields empty while the result stays under the form. The request goes to a mock endpoint the docs install in the browser. See Actions.

Action pipeline

Submit once to run the configured plugins in order.

const sequentialActionsDemoConfig: FormConfig = {
	id: 'action-demo',
	title: 'Action pipeline',
	description: 'Submit once to run the configured plugins in order.',
	steps: [
		{
			id: 'details',
			title: 'Action pipeline',
			elements: [
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email',
					inputType: 'email',
					rules: [
						{
							type: 'required',
							message: 'Email is required'
						}
					]
				}
			]
		}
	],
	view: {
		$type: 'card',
		shell: {
			appearance: {
				size: 'default',
				surface: 'elevated'
			}
		},
		header: {
			align: 'center',
			size: 'md'
		}
	},
	actions: [
		{
			id: 'submit',
			$type: 'submit',
			endpoint: '/api/submit-demo',
			method: 'POST',
			enabled: true
		},
		{
			id: 'notify',
			$type: 'show_notification',
			enabled: true,
			message: 'Submitted successfully',
			variant: 'success',
			triggers: [
				'form_submit_success'
			]
		},
		{
			id: 'reset',
			$type: 'reset',
			enabled: true,
			triggers: [
				'form_submit_success'
			],
			resetToDefaults: true
		}
	]
};

Copied shadcn source

This form renders with the registry's input field and card recipe, not with the demo kit. The docs app copies the same files, to the same target paths and with the same import rewrites that shadcn add applies, into src/generated/shadcn before dev and build; it does not run the CLI. The files are read from registry.json, the shadcn input, label and button come from this repository's own copies, and components are written as .react.tsx for the docs' React integration.

Contact us

Rendered by the copied shadcn input and card recipe.

const shadcnContactFormConfig: FormConfig = {
	id: 'shadcn-contact',
	title: 'Contact us',
	description: 'Rendered by the copied shadcn input and card recipe.',
	view: {
		$type: 'card',
		shell: {
			appearance: {
				size: 'default',
				surface: 'elevated'
			}
		},
		header: {
			align: 'center',
			size: 'md'
		}
	},
	steps: [
		{
			id: 'details',
			title: 'Contact us',
			elements: [
				{
					$type: 'input',
					id: 'name',
					name: 'name',
					label: 'Full name',
					rules: [
						{
							type: 'required',
							message: 'Name is required'
						}
					]
				},
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email',
					inputType: 'email',
					rules: [
						{
							type: 'required',
							message: 'Email is required'
						},
						{
							type: 'email',
							message: 'Enter a valid email'
						}
					]
				}
			]
		}
	]
};

The engine registers the copied field and recipe like any consumer's would:

import { createFormEngine } from '@schema-engine/forms';
import { InputElementRegistration } from '@/components/schema-engine/forms/inputs/form-input.registration';
import { CardRecipe } from '@/components/schema-engine/forms/recipes/registrations/card';

const engine = createFormEngine({
	elements: [InputElementRegistration],
	recipes: [CardRecipe],
});

The provider, the renderer and the copied field's hooks all import @schema-engine/forms-react from the one package, so they share one React context. A bundle that ends up with two copies of the package splits the context, and the field then throws a missing-provider error; keep one copy in your app. See Registries and View recipes for installing the source in your own app.