Schema validation
form0-core validates schemas before running the engine. Validation focuses on structure and attribute correctness, not UI concerns.
What is validated
- Required attributes per field type
- Allowed values for attributes (for example,
displayoptions) - Unique
keyanddata_name data_nameformat (lowercase a-z, 0-9, underscore, max length 42)- Default values match field type rules
- Condition operators are valid for the referenced field type
- AI metadata shape and allowed keys
Runtime validation
At runtime, each field checks its value when the engine evaluates. The result is in the errors map
of the engine state.
| Field | Accepted value | Also checked |
|---|---|---|
TextField | A string | pattern, if set |
NumericField | A finite number | min and max, and whole numbers when format is integer |
DateField | A real calendar date as YYYY-MM-DD, from year 0001 to 9999 | None |
TimeField | HH:MM or HH:MM:SS, with hours 00–23 and minutes and seconds 00–59 | None |
| Choice fields | Values defined in choices | None |
- form0 does not convert values, so
"12"in aNumericFieldis an error. null,undefined, and""count as empty, not as the wrong type. An empty optionalTextFieldalso skipspattern.- A value that fails stays in
valuesand appears inerrors, so a loaded record can still be inspected and corrected. - These checks run for every field, including hidden ones.
Try it
You need form0-cli.
-
Download a form with a
TextField, aNumericField, and aDateField:Code -
Run it with correct values. The output shows
"errors": {}:Code -
Run it with wrong values:
CodeEach field now appears under
errors:Code
Required fields and submission
The engine computes a required flag for each field, but it does not add an error merely because a
required field is empty. Required-field enforcement is a submission concern: the official
renderers combine visible, required, and the current value, skip hidden fields, and decide when
to display the error.
Check a submission
createRecordEvaluator().prepareSubmission() runs the calculations, selects the values to submit,
and applies the same checks as the official renderers. Use it on a server, or in any application
without a renderer. See Prepare a submission
for its options.
If you already have an evaluated snapshot, call
validateSubmission({ schema, snapshot, validationIssues }). It only checks: it does not
recalculate anything, and it does not remove unknown fields.
Both follow the same rules:
- By default, hidden fields and fields under hidden parents do not block a submission.
- A visible required field that is empty blocks a submission, even when it is read-only.
0and a selected No count as filled in.- A hidden repeatable section row takes no part in the check.
- A draft can be saved with validation errors. A handler that fails while running blocks drafts too.
- Validation handlers cannot change values or show alerts.
- These checks do not change
state.errors.LabelFieldandCalculatedFieldfollow their own rules.
The result includes a validationSummary:
| Property | Contains |
|---|---|
hasErrors | Whether anything failed. |
requiredFieldErrors | Required fields left empty. |
generalErrors | Values that fail their field's rules. |
scopeIssues | INVALID() messages, which belong to a record or row, not a field. |
orderedIssues | All of these in record order, with the main record before its rows. |
Each finding names its field by key and data_name, and its row by instancePath. An INVALID()
message from the main record stays with the main record, because form0 cannot tell which field it is
about. managedEvents: true also runs validation handlers for closed rows. Every failing row must
be corrected before a submission can pass, however many rows fail.
If a user keeps older calculated values during a review, the checks run on those kept values, including the conditions that depend on them.
Check hidden values on a server
By default, a submission ignores errors in hidden fields, because the user cannot see them. A client calling your API can put anything in those fields, so turn the check on in your server code:
Code
validateSubmission() takes the same option. With it on, a hidden value that fails its own rules
blocks the submission, such as a number in a TextField. This includes hidden rows. The other rules
stay the same:
- A hidden required field that is empty does not block, and validation handlers in hidden rows do not run.
- A draft can still be saved with these errors.
- When you continue a review with
decision, pass the same setting.
Each of these errors has hidden: true. To replace or clear the value in your own code, see
Resolve a hidden value.
This check covers values only. It does not remove unknown fields or decide who may submit. Add a form to an existing React app has a complete server example.
Typical errors
- Missing required attributes
- Duplicate
keyordata_name - Invalid operators (for example,
containson a numeric field) - Default values that do not match the field type