Values, snapshots, and submission
Initial values and overrides
Use initialValues for the record being edited. overrideValues take precedence and are useful
for values your application controls, such as a status from your backend.
For complete restoration, prefer initialSnapshot:
Code
An initial snapshot supersedes initialValues for raw field values. It also restores nested
repeatable section rows and client/server timestamps as
one coherent state.
Observe drafts
onSnapshotChange(snapshot, change) is called first with { kind: "seed", dirty: false }. Later
user changes use { kind: "change", dirty: boolean }.
The snapshot contains:
Code
Submit records
Use onSubmit to send a finished record to your API. FormRenderer calls it only when the form
passes validation.
Code
Code
onSubmit(record, meta) receives the structured record described in
Output and records. meta contains rawValues, repeatable, timestamps,
and validationSummary.
The save counts as successful when onSubmit returns or its promise resolves. To report a failure,
throw an error or reject the promise. fetch does not reject on a 500 response, so check
response.ok as in the example.
If the form runs in an overlay with autoCloseOverlayOnSubmit, the overlay closes only after a
successful save.
Use submitBlockedReason to disable Submit while something outside the schema is unresolved,
such as a request in flight. Use externalDirty for changes your application holds outside the
form.
For a complete example with a server, see Add a form to an existing React app.
Save failures and console messages
When a save fails, FormRenderer keeps the user's values so they can retry, and prints one
console.error report with the failure stage and the original error. It does not show a message to
the user, so do that in your application and then rethrow the error:
Code
If you catch the error without rethrowing it, FormRenderer treats the save as successful.
submissionDiagnostics controls these console messages:
Code
saveFailuresis on by default. Set it tofalseif your application already reports failures.validationBlocksis off by default. Set it totrueto log one line each time validation blocks Submit or a repeatable row's Save.
A required field left empty is a validation block, not a save failure.
Try it
- Click Submit with a required field empty. The field shows its validation message, and the console stays quiet.
- Add
validationBlocks: trueand click Submit again. The console shows[form0-react] Submit blocked by validation. - Fill in the field, make
saveRecordthrownew Error("Example save failure"), and click Submit. The console shows[form0-react] Submit failed during onSubmit.with your error, and your values stay in the form. - Remove the
throwand click Submit again. The save succeeds.
Details
- These settings take effect immediately, even while a save is pending. They are separate from
debug,engineOptions.diagnostics.console, and lifecycle settings. - Reports do not include form values, snapshots, or record paths. Preparation failures include their issue codes and messages.
- Cancelling a confirmation stays quiet. An exception thrown by your callback is reported as a callback failure.
form0-coreprints its own lines, such as[EVENT HANDLER] Registered. These settings do not control them.- These settings cover the renderer's built-in actions. If you call
prepareSave()directly, inspect the result it returns.
Use events from your own code
engineOptions.events sets which events run, and engineOptions.onEventController gives you a
controller for your own buttons. FormRenderer describes both in
full.
| Option | Default | Purpose |
|---|---|---|
events.recordKind | Required | "new" / "existing". |
events.lifecycle | true | Set to false to keep only load-record, edit-record, and change. |
events.fieldInteractions | ["focus", "blur", "click"] | Set to [] to turn off automatic interactions. |
onEventController(controller | null) gives you dispatch(request) and prepareSave(request).
prepareSave() never saves or closes anything. The returned summary lists validation messages for a
main-record draft. Validation failures block a normal submit and row acceptance, and calculation
diagnostics block nothing.
Review recalculated rows
When a user submits, FormRenderer recalculates saved rows automatically. Set
form.repeatable_recalculation to "confirm" in the schema when users should review changed values
first.
submissionOptions changes this from your code:
mode: "confirm"requires a review even if the schema does not."automatic"cannot turn off a confirmation set in the schema.allowRetain: truelets the user keep older values. It does not turn on a review by itself.messagesreplaces the review and status text.
The default review shows row titles and paths, field labels, old and new values, and counts, in pages. A choice applies to all changed rows or none. A save is rejected while a row editor is still open.
All validation findings stay available with their record paths, and the form pages them and links to
the record or field. An INVALID() message belongs to its record, not to a field.
Save the record and its freshness
Code
When your callback completes, form0 treats the save as successful. Save the record and
meta.freshness together before it resolves, and throw or reject on failure or cancellation.
freshness stays outside the form values. Pass the saved one back as initialFreshness. An older
acknowledgement cannot clear newer pending state. If a user keeps older row totals [110,220], the
submitted sum is 330, never the 360 of the refreshed proposal. If the user changes a value from
20 to 24, 24 stays as unsaved work even if validation or saving then fails.
Run a review from your own interface
A controller prepares a save without opening a dialog or saving anything:
Code
Check eligible, handle requires_decision, where payload is null, and acknowledge only the
preparationId you saved. getSaveChanges() returns 50 entries by default and at most 100. To
continue a review, call prepareSave() with
decision: { reviewId, action: "refresh" | "retain" | "cancel" }. Changing the inputs or
configuration, or starting a newer preparation, ends the review.
Validation runs before the save handler, which runs once for each attempt. If the handler changes values, a new review may be needed, but the handler does not run again.
In worker mode, pending reviews and reports stay in the worker. Replies contain the selected data and summaries, and you request change details in pages. Helpers that are functions are not supported in worker mode. Abort signals and callbacks stay out of the messages sent to the worker.
Setters follow the value rules. initialValues and overrideValues
are more tolerant, including in read-only mode, where calculated values stay as supplied.
Hidden values
A field with
visible_preserve_value: false
is cleared while the user edits, including in closed rows. It stays cleared in raw_values,
repeatable, and the submitted record. Other fields keep their values when hidden, and a read-only
form clears nothing.
To check kept hidden values on final submission, set validateHiddenValues:
Code
A hidden value that fails its own rules then blocks Submit. The user can fix it by making the field visible again, or your application can resolve it. Also check hidden values on your server. Drafts and empty hidden required fields are not affected.
Resolve a hidden value that fails validation
With validateHiddenValues on, a hidden value that fails its own rules blocks Submit, and the
user can't reach the field to fix it. The Validation tab explains this. To let your application
fix the value, pass onResolveHiddenValue. The tab then shows a Resolve hidden value button.
Code
Your handler receives fieldName, fieldKey, instancePath, message, and a copy of the current
value. It can return:
{ value: replacement }to replace the value, which must pass the field's own rules{ value: null }to clear itundefinedornullto cancel
The field stays hidden, no change or lifecycle handlers run, and nothing is saved until the user
clicks Submit. If the record changes while your handler runs, the reply is discarded and the
user has to submit again. Close any open row first. Read-only forms don't show the button.
If clearing the value leaves a row with no answers, the row stays in the record. See Saved empty rows.
Try resolving a hidden value
You need a React app with form0-react.
Add a form to an existing React app creates one.
-
Download the example form and render it. It has a hidden text field,
legacy_code, and this code loads a number into it:CodeCode -
Click Submit. The form is not submitted. Open the Validation tab. It shows
legacy_code must be a stringand says that the value is hidden. -
Click Resolve hidden value and cancel the dialog. Nothing changes.
-
Click Resolve hidden value again and confirm. The finding disappears, and the field stays hidden.
-
Click Submit. The browser console shows the record, with
legacy_codeset tonull.