Build forms with two-way binding
Signal has seven form controls, all bound to state the same way:
Input— typed text on one line, or several lines as a text area;NumberField— a number with a stepper, bounds and a currency, percent or unit format;Choice— one option from a fixed list (radio buttons, a select, a row of segmented buttons or a searchable combobox), or any number of them (checkboxes);Toggle— a true/false value, shown as a switch, a checkbox or a button that stays pressed while on;DateField— a calendar date, typed or picked from a calendar;DateRange— a start and an end date, picked as one range;Slider— a number picked along a range, such as a rating or a budget.
Nocturne has no form controls.
Bind an input
Section titled “Bind an input”Select the Input and, under Value, switch from Text to $bindState, then enter or pick a state path. The input shows the value stored there and writes each keystroke back:
"props": { "label": "Your name", "placeholder": "Full name", "inputType": "text", "required": true, "helpText": null, "value": { "$bindState": "/guest/name" }}- An Input with a literal
value, or none, is read-only at runtime. Only a$bindStatevalue is editable. $stateis refused onvaluewith a message pointing you at$bindState.- With
inputType: "number", a valid number is stored as a number, so comparisons such asgtkeep working against it. Other types store text. For an amount, a quantity or a percent, prefer aNumberField: it has bounds, a stepper and a format. - An Input whose bound value is an object or a list renders read-only and never overwrites it.
maxLength(optional, a whole number from 1 to 10,000) caps what a person can type or paste. It is the browser’s ownmaxlength, so it counts UTF-16 code units: an emoji may count as two. Like the platform, it has no effect withinputType: "number", and it only stops typing: a longer value already in state is shown whole. Mica never derives it from an object’s declared input; set it yourself, to the same limit when the Input feeds one.
A NumberField, Choice or Toggle binds the same way — its Value
switches from Static to $bindState — and follows the same rules: a static value, or
none, is read-only, $state is refused, and a bound one is editable.
Seed the target in the State tab first (an empty value is fine): $bindState stays unavailable until the document has a state key, and the suggestions list fields before containers.
Take a longer answer
Section titled “Take a longer answer”A reason, a note or dietary needs need more than one line. Give a text Input
lines, from 1 to 8, and it becomes a text area showing that many lines:
"props": { "label": "Reason for withdrawing", "placeholder": "", "inputType": "text", "lines": 4, "required": true, "helpText": null, "value": { "$bindState": "/drafts/withdraw/reason" }}Left out, null or 1, the Input stays one line. A text area binds, caps with
maxLength, marks itself required and shows its error exactly as a one-line
Input does, and the text it stores keeps its line breaks. Enter starts a new
line, so it commits only when the person
leaves it after a change. Import refuses lines above 1 on an email,
search or number Input. In the Inspector, Lines appears for a text
Input; picking another input type removes it.
Enter a number
Section titled “Enter a number”A NumberField takes a number a person types or steps with its − and + buttons
(or the arrow keys), and always stores the raw number — never text — or
null once they clear it:
"props": { "label": "Amount", "format": "currency", "currency": "EUR", "min": 0, "required": true, "helpText": null, "value": { "$bindState": "/trip/amount" }}formatdecides how the number reads while it is shown and typed; leave it out for a plain number."currency"needscurrency, an ISO 4217 code such as"EUR", and shows1250as “€1,250.00”."percent"stores a fraction, as$formatreads one:0.25shows as “25%” and steps by 1%."unit"needsunit, a unitIntlnames, such as"kilogram","hour"or"kilometer-per-hour".minandmaxare validated, never enforced by rewriting: the stepper stops at them, and a number typed or stored outside them is kept as it is and marks the field invalid.step(above 0) is how far each step of the stepper moves; 1 when left out. A typed number is never rounded to it.- The number is formatted in the person’s locale, the browser’s own; a host
that wants another wraps the surface in React Aria’s
I18nProvider. - Import refuses
currencyorunitwithout the format that shows it, a format without the one it needs,minabovemax, and a staticvalueoutside them. A bound value is never judged; a value that is not a number renders read-only and is never overwritten. - In the Inspector, Format picks the look; choosing currency or unit
brings in Currency (
EUR) or Unit (kilogram) to edit, and choosing another format takes it away.
The Choice in this example is a combobox and the reason is a text area:
Offer a fixed list of options
Section titled “Offer a fixed list of options”When a person picks from a known set — a priority, a size, a status — use a
Choice rather than a row of Buttons that each setState a value: three
options shown as buttons would otherwise take six Buttons (a selected and an
unselected look each), six conditions and three setState actions. Its
options are literal value/label pairs, in order, and display decides how
they look and what the value holds:
"props": { "label": "Priority", "display": "radio", "options": [ { "value": "low", "label": "Low" }, { "value": "normal", "label": "Normal" }, { "value": "urgent", "label": "Urgent" } ], "required": true, "helpText": null, "value": { "$bindState": "/drafts/ticket/priority" }}"radio","select"and"segmented"choose one option: the bound value becomes that option’svalue, text or a number exactly as written inoptions. Nothing is chosen until the person picks, or while the value matches no option."segmented"shows the options as one row of buttons, the chosen one filled in; it suits two to five short labels. Assistive technology reads it as radio buttons, and the arrow keys move between them."combobox"also chooses one, from a field a person types into: what they type narrows the list to the options whose label contains it. Use it for a long list a person would rather search, such as 30 countries. Clearing the text chooses nothing new: the chosen option’s label returns when they leave the field."checkboxes"choose any number: the bound value is a list of option values, always in option order, and[]once every box is cleared.- An option’s
valueis non-empty text or a number, and no two options may share one (1and"1"count as the same). Import refuses an empty or repeated list, and a staticvaluethat is not one of the options — or a single value on checkboxes, a list on radio, select, segmented or combobox. - In the Inspector, Options edits the list: type a value (digits give a
number,
"1"in quotes gives text) and a label, reorder, remove, or Add option. Display switches the look, and a static value follows it: it becomes a list for checkboxes and keeps its first entry for radio, select, segmented or combobox. Removing a chosen option un-chooses it.
Explain an option once it is chosen
Section titled “Explain an option once it is chosen”An option may carry a note: text shown under the Choice while that option is
chosen, and read with the control by assistive technology. A checkboxes Choice
shows the note of every chosen option, in option order; an option without one
shows nothing. Use it for what an option means — a shipping speed’s cost, why a
practice answer is right or wrong — instead of a Text per option with a
visible condition on the value.
"options": [ { "value": "standard", "label": "Standard", "note": "Free. Arrives in 4–6 working days." }, { "value": "express", "label": "Express", "note": "€9. Arrives in 1–2 working days if you order before 2 pm." }, { "value": "pickup", "label": "Pick up in store" }]A note is non-empty text of at most 500 characters; leave the key out for no
note. In the Inspector, each option row has a note field under its value
and label; clearing it removes the note. A note is only shown — it never
decides anything, so a quiz whose result counts is still graded by the host.
The gym induction quiz gives every answer a note.
To show the chosen option’s label away from the Choice, such as on a review
page, read it with $label.
A Choice edits only a value it can represent: nothing yet, one text or number
(radio, select, segmented, combobox), or a list of option values (checkboxes). Anything else in the
bound path — true/false, a record, or a list holding a value no option
offers — renders read-only and is never overwritten.
To send the choice to a host, give the declared input the same values as an
enum so the host is never asked with anything else. When the Choice’s value
binds a declared enum field, the Inspector offers Copy options from
customer.plan enum (the declared field’s label), which writes each enum
value as an option whose label is that value as text. Generate form from declaration
does the same, and uses radio buttons when there are four options or fewer,
otherwise a select. A checkboxes list cannot
be an object input yet — declared fields hold no lists — so bind it to ordinary
state; the host can read it there.
A condition compares a one-option choice with eq, as the
workshop sign-up example does. It cannot look
inside a checkboxes list, and an empty list still counts as holding something,
so show and hide things from a one-option choice or a Toggle instead.
Switch something on or off
Section titled “Switch something on or off”A Toggle binds a true/false value:
"props": { "label": "Call me back", "required": false, "helpText": null, "value": { "$bindState": "/drafts/wantsCallback" }}It writes true or false and shows off until the value is true. It edits
only nothing yet or a true/false value; anything else renders read-only. A
condition reads it directly: { "$state": "/drafts/wantsCallback" } holds
while it is on.
display decides how it looks; leave it out for a switch:
"switch"(the default) — a sliding switch beside the label;"checkbox"— a single box to tick, such as “I accept the terms”;"button"— a button that stays pressed while on, such as a “Follow” button.offLabelandonLabelgive its text while off and on (“Follow” / “Following”); without them it shows the label. With on or off text, assistive technology reads a plain button named by the text it shows, with the label as its description, since that text already says whether it is on. Without them it reads a toggle button named by the label that says pressed or not pressed.
"props": { "label": "Follow the keynote speaker", "display": "button", "onLabel": "Following", "offLabel": "Follow", "required": false, "helpText": null, "value": { "$bindState": "/day/following" }}One Toggle replaces a pair of Buttons with complementary visible conditions.
Import refuses onLabel or offLabel on a switch or a checkbox, which never
show them. In the Inspector, Display picks the look, and On Label and
Off Label appear once it is button; switching back to a switch or a
checkbox removes them.
Inside the template of a local list, { "$bindItem": "done" } lets each row
carry its own toggle — see lists.
Pick a date
Section titled “Pick a date”A DateField stores one calendar date as ISO "YYYY-MM-DD" text — the shape
a declared format: "date" field has, so the value can go straight into an
object input and $format shows it as a date:
"props": { "label": "Passport expires", "display": "picker", "min": "2027-05-06", "required": true, "helpText": "It must be valid for six months after you leave", "value": { "$bindState": "/trip/passportExpiry" }}A person types the date one part at a time (day, month and year, in the order
their locale writes them) or, with display: "picker", also picks it from a
calendar; leave display out for the typed field alone. The value is the
date once every part is filled, and "" while any part is empty, so a date
the person has partly cleared never stays in the state. Leaving the field or
pressing Enter commits a typed date, as an Input does; a date picked from the
calendar commits at once.
min and max are optional ISO dates. A date outside them shows the field
invalid with a message in the person’s language, and the calendar will not
offer it; import refuses a min after max, a literal value outside them and
any text that is not a real day ("2026-02-30").
A DateRange stores two dates, each in its own binding:
"props": { "label": "Stay", "min": "2026-11-01", "max": "2026-11-30", "required": true, "helpText": null, "start": { "$bindState": "/trip/checkIn" }, "end": { "$bindState": "/trip/checkOut" }}Both dates are typed, or picked from one calendar: the first click is the
start, the second the end. An end before the start shows the control invalid
with React Aria’s own message until the person fixes it; import refuses a
literal range that ends before it starts. It edits only while both sides are
bound, and each side writes "" while any of its parts is empty, as a
DateField does. A $calc daysBetween of the two reads counts the nights.
Neither edits a value it could not have written: text that is not a date, a number or an object renders read-only and is never overwritten. The date controls load the first time one renders, so a host whose documents show none never downloads the calendars (see the runtime API).
Pick a number along a range
Section titled “Pick a number along a range”A Slider binds a number between min and max, in steps (1 when left
out), and shows the value beside its label:
"props": { "label": "Nightly budget", "min": 50, "max": 400, "step": 10, "format": "currency", "currency": "EUR", "required": false, "helpText": null, "value": { "$bindState": "/trip/budget" }}format is "number" (the default), "currency" with an ISO 4217
currency such as "EUR", "percent" — of a fraction, as $format reads
it, so 0.25 shows as 25% and min, max and step are fractions too — or
"unit" with an Intl unit such as "kilogram" or "kilometer-per-hour".
Import refuses a currency or unit the format does not use, max not above
min, a step wider than the range or not dividing it into whole steps, a
left-out step where 1 does not divide the range into two steps or more (a
percent slider needs its own, such as 0.05) and a literal value outside the
range or off its stops.
Dragging writes as it moves and commits once, when the person lets go; each
arrow key press is a finished edit. The number shown and read out is always
the one stored: with nothing bound yet the slider shows no number, its thumb
at min, and the first drag or key press writes where it ends, min
included; a bound number outside the range or off its stops shows as stored,
marked invalid, its thumb at the nearest stop, and is never written back on
its own — a drag or key press writes the stop it ends on, that one included; a
value that is not a number renders read-only. In the Inspector,
choosing the currency or unit format brings in its Currency or
Unit field (seeded “EUR” and “kilogram”), and another format takes it out.
Choose the right target path
Section titled “Choose the right target path”Each keystroke — or each choice — replaces the whole target, so Mica requires
a $bindState target to name one field:
- It may not contain an array position such as
/tags/0. - It may not be a container of another path the document uses. If a Text
reads
/guest/name, binding an Input to/guestis refused — the first keystroke would blank the name — with a message naming the Text that reads it. - It may not write a path a declared business object owns (
/objects/{alias}/…or/meta/objects/{alias}/…). Edit a draft copy instead — see Load, create, update and delete records.
The rule looks only at paths, never at the current values, and it is checked in the inspector, on import, and whenever a later edit would create a conflict.
Mark a field required
Section titled “Mark a field required”The Required prop controls the Required marker next to the label. It is either Static (on or off) or When a condition holds:
"required": { "$cond": { "$state": "/drafts/wantsCallback", "eq": true }, "$then": true, "$else": false }The marker is presentation only. Mica checks required values for you in two
places: on the inputs of a business-object operation, where you declare them
as required or requiredWhen — see
Add field rules and writability — and on a form
control’s own Local rules, checked
by a Check local rules action without asking the host.
Make a field read-only for some people
Section titled “Make a field read-only for some people”The Writable prop decides whether a form control accepts edits: Static on/off, a State read, or Field writability, which reads what the host reports for a declared business-object field:
"writable": { "$state": "/meta/objects/customer/fields/contact.email/writable" }true or absent means editable; anything else, including false, means
read-only. A $state read of a path that holds nothing counts as absent, so the
control stays editable. In the designer’s preview no host is connected, so every
declared field reports itself not writable. The
customer profile example uses this to lock the
billing email while the name stays editable.
Show help and errors
Section titled “Show help and errors”helpText renders under the control. For errors, give any form control an
error: one $state read, typically the host’s field error for the
input the control’s value is sent as.
"error": { "$state": "/meta/objects/ticket/operations/create/error/fieldErrors/subject" }While the read holds non-empty text, the control shows it in the pack’s error
color under the field, is marked aria-invalid, and points aria-describedby
at the message, so a screen reader announces it with the field (a Slider marks
the thumb a person focuses). A Toggle
shown as a button only points aria-describedby at it: ARIA gives a toggle
button no invalid state. Anything else
— nothing yet, null, an empty or cleared error — shows nothing. error is a
read only: a literal message, $bindState or a row read is refused. In the
Inspector, Field error offers Show field error for… each create or update
input the control’s bound value is sent as — every control bound to that value
gets the offer. A read it does not offer, such as one an imported document
already holds, stays listed under its path until you pick another choice.
Elsewhere — near a submit, or on a page that has no control for the input —
add a Text that reads the error path and shows only when it holds something.
The inspector’s Show field error button on each input of an object action
sets the error of every control the input is sent from, and of every Value
that shows it, and adds such a Text
only where that slot cannot carry it: under a control whose error already
reads another path, or after the Button when no control sends the input.
When a form spans pages and its last page sends the write — a wizard with a
review step — a refused write leaves the person on that last page. Show each
input’s error twice, from the same path: in the error of the answer’s
Value on the review
page, where the person is when the host answers, and in the control’s error
on its own step, where they go back to fix it. The playbook’s
wizard pages recipe is a complete
example, and npm run mica:check hints
at every create input bound to a control whose error nothing shows.
Check a form without a business object
Section titled “Check a form without a business object”A form that writes ordinary document state can still check itself. Select an
Input, DateField, NumberField, Slider or Choice (Toggle has no rules) and
open Local rules. Tick Check this field to store rules on the
control — required, enum (placeholder one, two, three), and the same
constraints a declared input uses (pattern, min length, max length on
text; minimum, maximum on a number). requiredWhen stays on business-object
inputs. Bind the value with $bindState and the message with error. If
error is missing, or points somewhere local rules can’t write, enabling
rules points it at /errors/{key}; if it replaces an existing path, the
Inspector says so.
On the Button that should check the page, Add action and pick Check
local rules (validate, with empty params). That reserved action checks
only the ruled controls that are visible on the active page. Hidden
controls and other pages are left untouched and keep their error slots. With
none visible it succeeds. Each message (or "") is written to that control’s
error path; if any of those fail, the rest of the event does not run.
A host must register createValidateHandler with a live activePageKey
getter that returns the same key it gives PageProvider, and call
preflightLocalActions(document, handlers) before rendering — see
embed in a host. If the document
dispatches validate and that handler is missing, preflightLocalActions
reports it as not implemented; show that instead of rendering, or later
actions in the event would still run. A host action may not be named
validate: import refuses it as a reserved Mica action name.
Generate form from declaration
on an object with no write capability builds this shape for you: local
rules on each control that has them and, when any control has rules, a
Check button that dispatches validate.
Hold a Button until the form is ready
Section titled “Hold a Button until the form is ready”A Button’s Disabled prop is Static or When a condition holds, in the same form as Required. A step’s Next that waits on one answer is disabled until that answer is set:
"disabled": { "$cond": { "$state": "/form/shift", "not": true }, "$then": true, "$else": false }Conditions in a list must all hold; for “disabled while any of these is empty”,
give each value its own group in an
any-of $cond
({ "$or": [{ "$state": "/form/name", "not": true }, { "$state": "/form/email", "not": true }] }).
Several fields are clearer as a boolean
$expr
of Is empty / And / Or / Not on $cond. Next enabled when
name and email are both filled:
"disabled": { "$cond": { "$expr": "or", "args": [ { "$expr": "isEmpty", "args": [{ "$state": "/form/name" }] }, { "$expr": "isEmpty", "args": [{ "$state": "/form/email" }] } ] }, "$then": true, "$else": false}When Disabled already holds a formula, the Inspector shows the
Formula · … summary, Remove, and the formula editor — the same
formula mode as Show when.
Busy takes the same $cond + $expr shape; while a write runs, prefer
Busy’s Operation mode —
see show progress.
Act when a person finishes an edit
Section titled “Act when a person finishes an edit”An Input fires one event, commit: every time the person presses Enter, even
with the value unchanged (as a Button can be pressed again), and when they
leave the field if the value differs from what it was when they focused it or
last committed it. A commit whose actions were rejected (busy, superseded,
failed) did not land, so leaving the field fires it again. It never fires per
keystroke, and a state write — by an action or by the host — never fires it,
even when it changes the field.
An Input that is not editable never commits. A text area (an Input with
lines above 1) takes Enter as a new line, so it commits only when the person
leaves it after a change.
A NumberField, Choice or Toggle has no typing phase: it fires commit
on each change the person makes — a number typed and confirmed by leaving
the field or pressing Enter, each step, a new option, a box ticked or
cleared, a switch flipped, a toggle button pressed — after the new value is
written, so the commit’s actions read it. A state write never fires it, and one that is not editable never commits.
Its Events section is the same as an Input’s; a typical use is refetching
a list filtered by the chosen value.
A DateField or DateRange commits a typed date as an Input does — on Enter,
and on leaving the control changed — and a date or range picked from its
calendar at once. A Slider commits when a drag ends, or on each arrow key
press, on a new value; the value it wrote as it moved is already in state.
Select the Input: its Events section is the same one a Button has, with the same actions, the same limit of eight, and the same rules. The usual use is refetching a business object with what the person typed:
"on": { "commit": { "action": "fetch", "params": { "object": "orders", "inputs": { "customerId": { "$state": "/customerId" } } } }}The fetch reads the bound path, so it sends the value just committed. If the person commits again while that fetch is still running, the new fetch replaces it and only its answer lands — between fetches a person’s commits and presses start, the latest always wins. A commit that would start a fetch while a startup fetch, a fetch the host called itself, or a write on the same object is running is rejected as busy. The order history example loads a customer’s orders this way.
An Input inside a repeated template commits for
its own row: its actions can read that row’s fields with $item, nested in a
setState record or as an object input’s whole value, and with
{ "$bindItem": "title" } as its value it edits that field of a local row
first, so the commit reads the edit just made.