initForms / initFormsServer, the form instance methods, the React hooks, and the analytics events Forms emits. Which fields a form reads and writes depends on its schema.
Set up & use forms
In the browser, callinitForms; on the server, call initFormsServer. Each checks your Core setup once, then lets you open a form with getForm.
- JavaScript
- Server
core is required; the rest are optional. See Options below.getForm. Must be the id of a schema registered on Core. An unknown id throws a
FormsError. getForm returns one instance per form id — the first call builds it, every
later call returns that same instance.Options
Passed toinitForms. Per-form options (customValidations, serverFormData) are arrays keyed by formId.
core
Initialized Core instance with registered schemas
core
Initialized Core instance with registered schemas
@embeddables/core instance with at least one form schema registered (via
config.forms from em build, or forms on initEmbeddables). Init throws a FormsError if
Core is missing required methods or has no form schemas. Forms composes on Core for identity but
never reads or writes the identity entry.customValidations
Runtime validator functions for CLI-authored schemas
customValidations
Runtime validator functions for CLI-authored schemas
formId. Use this for CLI-generated
schemas, which cannot carry functions themselves (a schema must survive a JSON round trip; only
validations.custom may be a function). Each validator receives { value, values } and returns
a string, a list of strings, or null. An unknown formId or field key throws a SchemaError.serverFormData
SSR hydration seed from initFormsServer
serverFormData
SSR hydration seed from initFormsServer
initFormsServer().getServerFormData(). On overlapping keys, serverFormData overrides
localStorage; localStorage fills only the gaps. An unknown formId throws a SchemaError.analyticsInstance
Optional analytics client for event tracking
analyticsInstance
Optional analytics client for event tracking
.set()
emits data:updated plus one field:updated per changed field, and .submit() emits
form:submitted — see Analytics events. A rejected trackEvent() never fails
a .set() / .submit(); the failure surfaces as trackError on the result. In React, the CLI
wires Analytics into Forms automatically from Core — pass analyticsInstance only to override that
default. Omitting it disables event tracking; durable saves still run when Core resolves
persistence config.Methods and hooks
React covers theforms() module factory and the hooks — register the factory on EmbeddablesProvider before calling hooks. JavaScript & Server lists methods on the form from initForms or initFormsServer — the same names on both entry points; SSR uses in-memory storage only (no localStorage, durable save, or Analytics on .set() / .submit()). After set, submit, or validate, check result.ok and result.errors — a failed validation does not throw an error.
- React
- JavaScript & Server
@embeddables/forms/react. Register Forms on EmbeddablesProvider’s modules prop with the forms() module factory, then bind fields with these hooks. Every hook returns null / empty state until Forms is ready — handle that before calling instance methods.forms()
Module factory for EmbeddablesProvider
forms()
Module factory for EmbeddablesProvider
EmbeddablesReactModule for the provider’s modules prop. The generated CLI setup
wires this for you; pass options only to override. core is supplied by the provider — do not pass
it here. Form schemas must be on config (from em build), not on forms().initForms.initForms — typically SSR hydration seed.useForm()
Reactive form, values, and errors for one form
useForm()
Reactive form, values, and errors for one form
em build augments.null until Forms is ready. Every useForm with the same
id shares one instance.useFormField()
Commit-on-blur binding for one field
useFormField()
Commit-on-blur binding for one field
useFormErrors()
Just the reactive validation errors
useFormErrors()
Just the reactive validation errors
useForm. Returns the reactive FieldErrors map.Analytics events
Emitted automatically only when ananalyticsInstance is wired (directly, or via the CLI in React). Each is a standard Analytics event — see the Analytics event reference for the full field list.
data:updated
Emitted once per successful set(), carrying every changed key
data:updated
Emitted once per successful set(), carrying every changed key
value (stringified, max 1024 chars) and label (the field’s
label, max 256 chars).field:updated
One per changed field on set()
field:updated
One per changed field on set()
form:submitted
Emitted once per successful submit()
form:submitted
Emitted once per successful submit()
data:updated / field:updated events, not
on this event.Returns
getForm returns a FormInstance. Its write methods resolve to result objects that never reject on validation failure.
true when the operation succeeded. set, submit, and validate all return it.submit and validate results — the current stored values.set / submit results only when an analyticsInstance was configured and its
trackEvent rejected. The field values are still persisted; the error is reported, never thrown.
