Installation and quick start
This page builds a contact form: an engine with the elements of a renderer, a form config loaded as JSON, the issues a bad config reports, and the form drawn on the page with its values handed to your code. It renders with Forms Radiant. The same engine and config render with Forms React once you register elements that draw with React.
Install
pnpm add @schema-engine/forms @schema-engine/forms-radiant @schema-engine/layout @schema-engine/registry @ecopages/radiant-ui @ecopages/radiant @ecopages/jsx @ecopages/signals zodZod provides the zod/mini entry point the first-party schemas use. Registrations may use any Standard Schema validator. Radiant renders with its own JSX runtime and three stylesheets: Forms Radiant sets them up. The React quick start has the equivalent setup for React.
1. Create the engine
createFormEngine builds an engine from lists of registrations: the elements a form may use, the recipes that frame it, the actions it may run and the validation rules. A renderer supplies the elements that draw. createRadiantFormEngine is createFormEngine with the Radiant elements and view recipes registered, and schemaFormRegistrations is the list of elements. To write an element of your own, see Engine and registrations.
import { createRadiantFormEngine, schemaFormRegistrations } from '@schema-engine/forms-radiant';
export const engine = createRadiantFormEngine({ elements: schemaFormRegistrations });2. Check a form loaded as JSON
A form config is data, so it can come from a file or a server. engine.validateForm checks it and returns a frozen NormalizedFormConfig, or throws a FormValidationError. engine.safeValidateForm returns { success, data } or { success: false, issues } instead. Each issue has a message and the path of the config key it is about. See Form configuration errors.
import { engine } from './engine';
const contactJson = `{
"id": "contact",
"steps": [
{
"id": "details",
"title": "Your details",
"elements": [
{ "$type": "input", "id": "name", "name": "name", "label": "Name", "rules": [{ "$type": "required" }] },
{
"$type": "input",
"id": "email",
"name": "email",
"label": "Email",
"inputType": "email",
"rules": [{ "$type": "required" }, { "$type": "email" }]
},
{ "$type": "submit", "id": "send", "name": "send", "label": "Send" }
]
}
]
}`;
export const contact = engine.validateForm(JSON.parse(contactJson));A config with mistakes is reported, not thrown, by safeValidateForm. This one names an element type nobody registered and leaves out a field's required name:
import { formatIssuePath } from '@schema-engine/registry';
import { engine } from './engine';
const brokenJson = `{
"id": "contact",
"steps": [
{
"id": "details",
"title": "Your details",
"elements": [
{ "$type": "phone", "id": "phone", "name": "phone" },
{ "$type": "input", "id": "name" }
]
}
]
}`;
const result = engine.safeValidateForm(JSON.parse(brokenJson));
if (!result.success) {
for (const { path, message } of result.issues) console.log(`${formatIssuePath(path)}: ${message}`);
}steps[0].elements[0].$type: No registration for $type 'phone'. Register it with createFormEngine({ elements: [...] }).
steps[0].elements[1].name: Invalid input: expected string, received undefinedBoth problems are reported at once, each with the position of the key to fix.
3. Render it
The renderer draws the config and owns the form's state. FormRenderer validates the config, renders it and calls onSubmit with the values that passed validation:
import type { FormValues } from '@schema-engine/forms';
import { FormRenderer } from '@schema-engine/forms-radiant';
import { contact } from './contact';
import { engine } from './engine';
export function ContactForm({ onSubmit }: { onSubmit: (values: FormValues) => void }) {
return <FormRenderer engine={engine} config={contact} onSubmit={onSubmit} />;
}With both fields empty, a submit shows the required messages and onSubmit is not called. Once the visitor fills them in, onSubmit receives { name: 'Ada Lovelace', email: '[email protected]' }. Send the values with the fetch that onSubmit is given, or name a submit action in the config and let the engine post them. Forms Radiant covers the styles, the server-side rendering and the controls.
Where to go next
- Engine and registrations: authoring modes, configuration errors, view recipes.
- Forms React or Forms Radiant: draw this form with the renderer you use.
- Validation: the 27 rules and your own.
- Actions: the actions a form ships.