FormRenderer
FormRenderer validates and prepares a schema, creates the form engine, renders fields and
sections, and produces structured records on submission.
Code
Essential properties
| Property | Purpose |
|---|---|
schema | A form0 schema containing form.elements. |
initialValues | Initial non-repeatable field values. |
initialSnapshot | Restore raw values, repeatable state, and timestamps together. |
overrideValues | Apply authoritative values over initial values. |
onSubmit | Receive the structured record and submission metadata. |
submissionDiagnostics | Control save-failure reports (on) and routine validation-block messages (off). |
submissionOptions | Set review options, messages, and validateHiddenValues. |
onResolveHiddenValue | Let your application fix a hidden value that fails validation. |
initialFreshness | Restore a record's saved freshness. |
eventDiagnostics | Control failed-event reports (on). |
onSnapshotChange | Observe seed and user-change snapshots. |
mode | Start in edit or readonly mode. |
repeatableEntryMode | Opening mode for existing repeatable section rows: readonly (default) or edit; new rows start editing. |
formWidth | Maximum form width, such as 100%. Defaults to 30vw. |
Consumer-owned UI and state
headerAccessoryrenders a React node, or a function receiving{ mode }, between the summary and form body.recordMetadataFieldsdisplays read-only record metadata. A descriptor withdisplayValuenever enters engine values, snapshots, or submitted values.externalDirtyincludes application-owned changes in overlay discard confirmation.submitBlockedReasondisables and guards submission while an external requirement is unresolved.onSchemaReadyreceives the prepared schema after stable keys have been ensured.
Form element properties
Additional standard form properties such as id, aria-*, and event handlers are forwarded to
the rendered <form>. Do not use this path for engine configuration.
Continue with Values, snapshots, and submission or Modes, placement, and navigation.
Engine options and calculation diagnostics
engineOptions passes helpers, security settings, onWarning, onUpdate, onOperations, and
calculation diagnostic settings to the main engine and to row engines. Helpers and security are set
when the engine is created, so remount FormRenderer to change them. Callbacks and the console
setting update in open editors without another evaluation.
Code
Console reports are on by default. diagnostics.console: false turns off calculation details and
recovery and scope-ended messages in the console, while collection and callbacks continue. Adding
onDiagnostics does not turn console reports off. Console headings are in English.
onDiagnostics(snapshot, meta) receives a copy of the findings after each completed evaluation,
including the first one, repeated findings, and [] after recovery. The console skips identical
repeats and reports new or changed findings, recovery, and problems that come back. An error in your
callback, including a rejected promise, cannot interrupt evaluation.
meta contains scopeId, instancePath, evaluationId, and kind. A scope is the lifetime of
one engine, and evaluation IDs increase within it. The main record's path is []. Each row segment
has repeatableKey, instanceId, a zero-based index, and identity: "id" | "position". form0
uses a row's id or record_id, and falls back to its position. Findings carry the same path in
context.instancePath. Reporting never creates record IDs.
Closing or deleting an editor, replacing its engine or schema, or unmounting ends the scope with
onDiagnostics([], { ...meta, kind: "scope-ended" }). That means the scope is no longer observed,
not that the row recovered. Only engines that evaluate are reported, so this callback is not a full
health report, and it does not evaluate closed rows again.
Calculation diagnostics stay out of state.errors, saved snapshots, and records. They do not change
validation, submission, or draft saving, and they add no alerts or panels.
Handle operations and warnings
onOperations(operations, meta, applyDefault) receives every operation except alerts. Pass the ones
you want handled normally to applyDefault(selected, meta). Without the callback, the default
handling applies. The renderer shows each ALERT once. Your callback must handle every batch it
receives.
onWarning receives engine warnings, which can be throttled, and does not replace onDiagnostics.
onUpdate(state, engine) receives the state and an engine object whose type depends on how the form
runs. If you only need diagnostics, use onDiagnostics.
Events and custom validation
Lifecycle events and field interactions are on by default. Use recordKind to say whether the form
holds a new or an existing record:
Code
recordKind must be new or existing, unless you set lifecycle: false. form0 does not work it
out from the values. These settings last for the life of the editor, so remount to change
recordKind, lifecycle, helpers, or security. Callbacks stay live.
- A read-only form runs
load-record. An editing form runsload-record, thennew-recordoredit-record. - Open rows use the repeatable events, with the row's own new or existing kind.
lifecycle: falsekeeps onlyload-record,edit-record, andchangefor the main record.fieldInteractions: []turns off automatic interactions.- Text and numeric inputs emit
focusandblur, and choice fields usechange. No built-in control emitsclick, so dispatch it through the controller.
The event controller
onEventController receives a controller after the form initializes, and null when that
controller is retired:
dispatch({ type, fieldKey?, instancePath?, scopeId?, metadata? })returns a promise withstatus,operations,validationIssues, andissues, after accepted operations finish.prepareSave({ intent: "submit" | "draft", instancePath?, scopeId? })returns a promise witheligible,payload,meta,validationSummary, andissues. It never saves or closes anything.
Field listeners use data_name, and paths use schema keys and row IDs. A position-based path needs
the active scopeId from diagnostics. Closed targets and retired controllers are rejected.
Custom validation
INVALID(message) adds a message to a record or row during validate-record or
validate-repeatable. Messages join the validation list and its navigation, are replaced on each
attempt, and clear when data changes or the editor closes. They never enter state.errors,
calculation diagnostics, values, or record metadata.
Validation and close handlers cannot change values, show alerts, or return promises. Row handlers
can read the current main-record and parent fields, but SETVALUE writes only to their own row, and
repeatable collections are out of reach.
How a save is prepared
- Wait for pending updates.
- Validate.
- Run
save-recordorsave-repeatableonce, if validation allows it. - Wait for its operations to finish.
- Validate again if values changed.
- Build the record from that final snapshot.
Submit and row acceptance stop on validation failures. A main-record draft continues with
hasErrors: true, and rows have no drafts. If a handler fails, no payload is returned. isDraft
describes the current action, and isValid is the built-in validity. Calculation diagnostics alone
never block a save.
When events run
User edits emit change after updates settle. Accepted row changes add action (add, edit, or
remove) and affectedInstancePath. An enabled status field emits change-status for user changes
only. Defaults, SETVALUE, and calculations do not emit change. form0 waits for async
onOperations and applyDefault work. The fallback expires with its dispatch.
A confirmed cancel runs the cancel event and then the unload event. A successful close runs the
unload event before the editor is removed. If your application closes an editor directly, dispatch
the unload event before you unmount it. Rerenders, resets, React Strict Mode cleanup, and forced
unmounts do not count as closing. save-record and save-repeatable run before saving, and there
are no saved-* schema events. Your application handles saving, success messages, and closing.
File and Blob uploads keep their standard metadata and content. Custom properties on them are
not kept.
Event failure reports
eventDiagnostics controls console reports for failed events, separately from
submissionDiagnostics:
Code
A failed event logs one console.error by default, including a rejected SETVALUE() and a rejected
onOperations promise. The report has the event type, the field, the main-record or row scope, and
issue codes and messages. It has no values, operation arguments, snapshots, or record IDs. Set
failures: false if your application handles these reports. The setting updates in open editors and
pending operations.
Validation messages and INVALID() are not failures, and cancelled work stays quiet. Submit and
a row's Save use the submission reports, so you do not get two. If you call prepareSave()
directly, inspect its result. dispatch() returns its result even when console reports are off.
These settings do not control form0-core warnings or the console output with lifecycle: false.
Numeric fields take numbers, such as SETVALUE("quantity", 1). Choice fields take string IDs:
SETVALUE("rating", "1") for single selection and SETVALUE("tags", ["1"]) for multiple selection.
A rejected call leaves its whole batch unapplied. Reporting changes no values, validation, records,
or evaluation counts.
Try it
-
In a schema with a
SingleChoiceFieldnamedrating, add this handler toform.events.code:Code -
Open the form. rating stays empty, and the console shows
[form0-react] Event failed. -
Replace
1with the string ID of one of the field's choices, and open the form again. The choice is selected, and the console shows no report.