Forms

Forms is the first domain of Schema Engine. It uses the registry for its elements, recipes and validation rules, actions for submit, reset and the work around them, and layout for the grid and named appearance. On top of those it adds what a form needs: fields and their values, validation rules, constraints between fields, steps, form state and the submit lifecycle. A form is a document: a JSON config that names registered elements by $type.

You build a form with createFormEngine from @schema-engine/forms and draw it with a renderer: Forms React or Forms Radiant. Both draw the same config, and the engine owns what the config means.

With the engine you can:

  • Author form configs in TypeScript with engine.defineForm(), typed from your registrations, or load them as JSON and check them with engine.validateForm().
  • Register your own elements, view recipes, actions and validation rules.
  • Validate values with the 27 validation rules the engine registers, and with rules of your own.
  • Generate JSON Schema from what the engine has registered, for editors and tools.

What a form can do

A form's behavior is independent of the element that collects a value and the recipe that lays out the form. Every renderer implements the same form configuration contracts.

CapabilityUse it forStart here
ConstraintsShow, hide, enable, disable, or require a field from another valueConstraints
ValidationRequired values, formats, ranges, and custom rulesValidation
ActionsSubmit, reset, notifications, and ordered side effectsActions overview
Async validationDebounced remote checks, dependency values, and failure handlingAsync rule
Async actionsPending, success, and failure states around a remote operationSubmit, notify and reset
Dynamic fieldsRepeatable groups and nested field scopesRegister a container
Form stateValues, field state, validity and submission, the same in both renderersForm state
Wizard stepsNext, back and jump, with steps skipped from earlier answersWizard
Server errorsShow a server's validation response on the fields it namesServer errors
Issue textWord every error and warning in your languageIssue text
CSRFSend a token with the engine's requests and native postsCSRF

Installation and quick start

pnpm add @schema-engine/forms zod

Installation and quick start creates an engine with the elements of a renderer, checks a form loaded as JSON and renders it. The zod package provides the zod/mini entry point that first-party schemas use. Registrations may use any Standard Schema validator.

Where to go next

  • Installation and quick start - Create the engine, check a form loaded as JSON and render it
  • Engine and registrations - createFormEngine, registrations, typed authoring and configuration errors
  • Constraints - Show, hide, enable, disable or require a field from another value
  • Validation - The 27 built-in rules and presets
  • Custom and async rules - Your own rules, a server check and testing
  • Actions - The actions a form ships and how its submit runs them
  • Form state - What a form holds, and how to read it from React and Radiant
  • Issue text - Word errors and warnings in your language
  • Wizard - Step navigation, skippable steps and a stepper of your own
  • Server errors - Show a server's answer on the fields it names
  • CSRF - Send your framework's token with requests and native posts
  • Other React state - Mount a form in a panel that holds other state
  • For AI agents - The guide an AI agent reads, shipped in the package
  • Browser helpers - Consent-aware drafts and analytics events
  • Write a renderer - For the author of a renderer: the runtime and the state container
  • Agent tools - Offer a rendered form to a browser agent as a WebMCP tool
  • Layout - Grid, appearance axes, theming and copy-paste examples
  • YAML forms - Author forms in YAML with errors that point at the line
  • API reference - Complete API documentation