Live preview server
Run form0 serve [schema] to start the local preview server. It uses port 3030 and binds to
localhost by default; --port and --host override those values.
The preview server is a development tool. Use trusted projects and connectors, and only expose it to a trusted network.
How the preview applies values
The preview follows the same value rules as the official bindings:
SETVALUE()and programmatic updates are checked as one batch. If one is rejected, none is applied.- An unknown string selection stays in the field, so validation can report it.
- A read-only record blocks event writes, including during
load-record. A field's ownread_onlysetting does not, so code can still change that field.
Calculation diagnostics in the browser
The server returns diagnostics with each evaluation. The browser console shows new or changed findings, resolved findings, and problems that come back. Identical evaluations do not print them again. A finding in a nested repeatable section row shows its repeatable path and row ID, or says that it uses a row position when there is no ID.
Use form0 serve [schema] --no-diagnostics to hide calculation reports and built-in preview console
output. Diagnostics are still collected. An app started with serve --app keeps its own reporting.
A calculation that completes still returns state when its diagnostics contain errors. Diagnostics do not add form alerts or block submission, and field validation, events, and draft saving work as usual.
Record preview and lifecycle events
A new preview starts as a new record, with lifecycle events and field focus and blur events on. To change how it opens, go to Form Settings > Record preview:
- New record runs
new-recordhandlers. This is the default. - Existing record runs
edit-recordhandlers. It does not load a database record, it only chooses which handlers run. - Open read-only runs
load-recordinstead ofnew-recordoredit-record. Fields are grayed out and can't be edited, and Submit Record is disabled.
Advanced event settings has the switches for turning events off, and a saved choice stays in
place. Changing these settings starts a new session with the values already accepted. An app started
with serve --app keeps its own options, and standalone commands such as form0 run keep their own
defaults.
What runs and when
- When a record opens, the form evaluates,
load-recordruns, and thennew-recordoredit-recordruns. - When a user edits a field,
changeruns after queued updates settle. In a text field, that means every keystroke. - Defaults, calculations, and
SETVALUE()do not addchangeevents. - Text and numeric inputs emit
focusandblur, and choice fields usechange. - An enabled status field emits
change-statuswhen a user changes it. - No built-in control emits
click. Dispatch it yourself through the controller described below.
What happens on submit
- Built-in and custom validation run.
save-recordruns once.- Validation runs again, only if values changed.
- The final record is built and sent to any connector.
INVALID(message) adds a message to the validation list without changing state.errors.
Calculation diagnostics alone do not block a submission. There are no saved-* schema events.
Submit logs the final record and each connector's outcome to the console. A connector or storage failure does not count as a saved result.
Try it
You need form0-cli.
-
Start the preview with an example form:
Code -
Open
http://localhost:3030, enter10in Amount, and click Submit Record. -
Open the browser console. It shows
[STRUCTURED RECORD] Record prepared, and thenNo database connector configured; record prepared for preview only.
Try a read-only record
You need form0-cli.
-
Start the preview with the example form. If it is already running, go to the next step.
Code -
Open
http://localhost:3030and click ⚙ to open Form Settings. -
Under Record preview, select Open read-only and click Save.
-
Click Amount and type a number. Nothing appears. City can't be opened, and Submit Record is disabled.
-
Reload the page. The form is still read-only, because the setting is saved in your browser.
-
Open Form Settings again, clear Open read-only, and click Save to edit the form again.
The preview shows no read-only banner, so look for the disabled (grayed-out) fields and Submit Record button.
Repeatable section rows
Inline rows offer Edit, Save row, and Cancel row. Edits stay staged until you accept them: Save row validates the row first, and Cancel row discards its staged nested edits. Collapsing a row only changes how it looks.
Row handlers use the repeatable events. They can read permitted parent and main-form fields, and they write only to their own row. Adding, editing, or removing a row notifies the repeatable section that owns it. A problem in that notification is reported separately, and the accepted row stays.
Closed rows are prepared with the rest of the record on submit, without replaying their editing events.
Advanced actions
Advanced preview actions is a collapsed section with three actions:
- Prepare draft prints a raw snapshot and any validation summary to the console. It never saves the draft or calls a connector.
- Cancel record discards editor changes.
- Close record runs the unload lifecycle.
Cancelling or closing notifies handlers before the session ends. Reloading the page ends it without notice, and reopening starts a new session. A disabled nested row control explains which parent editor to open first.
Control the preview from the console
window.form0PreviewEvents is a developer controller for the active preview:
dispatch()runs an event and returns its findings and issues.prepareSave({ intent: "submit" | "draft" })prepares a save without submitting or closing anything.
To target a row, pass its complete instancePath and the scopeId shown as data-preview-scope-id
on the page. A position-based path requires that ID. Metadata must be JSON, so executable
configuration and native file handles are rejected. Saved values contain no scope or diagnostic
data. The controller does not change the exit status of terminal commands.
Draw in a BuildingPlan
Drawing in a BuildingPlan canvas opens an Edit draft of the floor. Rooms, walls, openings, and other geometry appear right away as rows. Save row validates and accepts the floor, and Cancel row restores its geometry and rows together. Required survey questions still need answers.
Before you draw again, accept or cancel any open room or wall editor. Finish the floor draft before
you submit the main record. Collapsing or switching floors does not save. Read-only records and
read-only BuildingPlan sections disable drawing. Drawing does not change the schema or record
format, and it does not let SETVALUE() write across records.
Review recalculated rows
Set form.repeatable_recalculation to "confirm" in the schema to review changed calculations in
saved rows when you submit the main record. If you leave it out or use "automatic", they refresh
automatically. There is no switch for this in the preview settings.
An open row keeps recalculating with its parents' current values, so accept or cancel it before you submit. Keeping older values also needs the server permission described in the next section.
The preview uses the same checks with lifecycle events on or off. With events off, custom validation and save handlers stay off.
Save preview records
createApp() accepts server-side submissionOptions and an optional storageAdapter, so you can
test saving and restoring records in your own preview server:
Code
The adapter implements two async methods:
load(identity)returns{ record, freshness }ornull.save(identity, { record, freshness })stores them.
record uses the structured record format. To restore a record, the session uses recordIdentity
or recordOptions.mainRecordId, including ID zero. The example adapter replaces a local file
atomically. In production, your application decides how to handle revisions and conflicts.
allowRetain requires an adapter, and browser requests cannot grant it. A successful save
acknowledges the preparation. If it rejects, stores only part of the data, or a connector fails, the
attempt stays unsaved. Connectors receive the same record as usual and do not store freshness. A
client that only prepares a save must acknowledge a successful external save itself.
getSaveChanges() returns review details in pages, and a decision applies to all changed rows or
none.
Hidden values in the preview
The preview applies the same value checks and
visible_preserve_value
rules as the bindings, including in closed rows.
CSV export and import keeps the attribute.
To check hidden values on submit, set the option on the server. Browser requests cannot change it:
Code
Resolve a hidden value
To let the preview fix a hidden value that fails validation, pass onResolveHiddenValue to
createApp(). The validation findings then show a Resolve hidden value button.
Code
The handler runs on your server, so it can't open a browser dialog. form0 serve has no option for
it.
Resolve a hidden value
in the React docs explains what the handler receives and returns.
If clearing the value leaves a row with no answers, the row stays in the record. See Saved empty rows.