Forms
A form defines how a user supplies inputs for a command. A screen’s action exposes the command; the form supplies its fields. Declare the form once at module level with for <Command> so you can reuse the same input surface wherever that command is invoked.
Use description to explain the form to someone reading the model. A form accepts one quoted or fenced-text description body line, which prints before populate and fields. It is report-only authoring metadata, not a localizable UI label. Individual fields do not accept descriptions, and forms do not support Markdown documentation.
populate via query ... by value and on submit navigate ... by value remain scalar lookups. They cannot supply a composite read-model key. A single-instance composite lookup reports PLAY0661; no automatic form repair is offered. See Read-model keys.
Syntax
Section titled “Syntax”form <Name> for <Command> populate via query <Query> [by <param>] # -- or -- populate from item
generation auto|manual
field <property> [from <source>|compose using <Callback>] [label "<text>"] ...
columns auto # -- or -- columns manual column <property> [label "<text>"]
layout column <index> [width <width>] [min <width>] [max <width>] columnGap <width> rowGap <width> place <field> row <row> column <column> [rowSpan <n>] [columnSpan <n>] [width <width>]
on submit navigate to <Screen> [by <param>]form <Name> for <Command>- top level, alongsidescreen templateandfeature, inside amodule. A module can declare more than one; each name must be unique.populate- where the form’s initial values come from. At most one per form, and optional - a form with nopopulatestarts empty.generation- preserves Scene’sFormGenerationMode:automeans generate fields from command metadata, whilemanualmeans the authored fields are the contract. At most one per form.field- binds one of the command’s properties to the form. Zero or more.columns- which command properties the form shows, in which order and with which labels.columns autolets the package infer them, whilecolumns manuallists the command properties in display order. At most one per form.layout- Scene 4.12 command-form geometry: authored columns, field placements and gaps. It is independent ofgenerationand does not reinterpretcompose usingas layout metadata.on submit- what happens after a successful submit. At most one per form, and optional - a form with noon submitstays on the current screen.
Example
Section titled “Example”form RegisterInvoiceForm for RegisterInvoice populate via query GetInvoiceDraft by invoiceId
field customerName field dueDate label "Due date" field totalAmount from calculatedTotal field lineItems compose using BuildLineItems
generation manual columns manual column customerName label "Customer" column dueDate label "Due date" column totalAmount
layout column 1 width 1fr min 240px max 50% column 2 width 2fr columnGap 24px rowGap 16px place customerName row 1 column 1 width auto place dueDate row 1 column 2 width 100% place totalAmount row 2 column 1 columnSpan 2
on submit navigate to InvoiceList by invoiceIdpopulate via query GetInvoiceDraft by invoiceId supplies the initial values in this example. The fields bind those values to the command’s inputs; totalAmount takes its value from calculatedTotal, while lineItems uses the BuildLineItems callback. Navigation happens only after the command succeeds.
A form is discovered, not referenced
Section titled “A form is discovered, not referenced”The for RegisterInvoice binding connects this form to its command. An action RegisterInvoice on any screen discovers RegisterInvoiceForm automatically, so you do not put the form inside a screen’s directive tree as you would a table or summary. Like a ui profile discovered by a build, the form is selected through its binding rather than named on each screen. You maintain the command’s input surface in one place.
Populating a form
Section titled “Populating a form”Use populate via query <Query> [by <param>] to seed initial values from a query result, using the same shape as a screen’s data directive. If the item is already bound in scope, use populate from item instead. That can reuse the row a table’s on row-click navigated from without introducing a new binding mechanism; the name follows the ordinary resolution rules.
Fields
Section titled “Fields”A bare field <property> binds straight to the command property of the same name. Three optional refinements adjust that:
| Form | Meaning |
|---|---|
field <property> label "<text>" |
Overrides the display label. |
field <property> from <source> |
Binds from a differently-named source property. |
field <property> compose using <Callback> |
Computes the value from a callback instead of binding it directly. |
from and compose using are mutually exclusive on one field; either may still carry a label. A field’s label accepts an unquoted $strings.<key> token in place of a literal, the same as everywhere else in the document - see Internationalization.
Pickers
Section titled “Pickers”A field that chooses one of the rows a list query returns says so on the line under it:
concept CategoryId : Uuid
module Catalog form DraftProductForm for DraftProduct field category choose from query AllCategories show name field supplier
feature Products slice StateChange DraftProduct command DraftProduct sku String identifier category CategoryId supplier String produces ProductDrafted for sku event ProductDrafted sku String screen DraftProduct action DraftProduct
slice StateView Categories readmodel CategoryRow id CategoryId key name String query AllCategories => CategoryRow[]choose from query <Query> show <field> makes the field a picker over the query’s rows, showing <field> of each. The query must return a list, and its rows must have the field (PLAY0913); an unknown query is PLAY0196.
A field is a picker without the line when its command property’s concept is the key of a read model exactly one list query returns: category CategoryId above would be inferred to choose from AllCategories, showing the read model’s name or title field, or else its first field that is not the key. Write the line when two list queries return the read model, or to show another field.
Columns and layout
Section titled “Columns and layout”columns and layout answer different questions and can be used together: columns decides the order and labels of the fields, and layout decides their geometry. Neither replaces the other.
Use columns auto when the native command form runtime should derive the display order from the command and package defaults. Use columns manual when the business order matters or the screen needs deterministic columns across packages.
form RegisterInvoiceForm for RegisterInvoice field customerName field dueDate field totalAmount
columns manual column customerName label "Customer" column dueDate label "Due date" column totalAmountA manual column names a command property already present in the form. The compiler preserves the column order and labels for renderers; a renderer that cannot honor manual columns must diagnose that mismatch instead of silently reverting to an automatic layout.
layout carries the richer Scene 4.12 geometry contract. Widths use the same units as Scene: auto, fractional units such as 1fr, pixels such as 240px, and percentages such as 50%. Column indexes, rows and columns are one-based for authored stability. rowSpan and columnSpan are optional positive integers.
form RegisterInvoiceForm for RegisterInvoice generation manual field customerName field dueDate field totalAmount
layout column 1 width 1fr min 240px max 50% column 2 width 2fr columnGap 24px rowGap 16px place customerName row 1 column 1 width auto place dueDate row 1 column 2 width 100% place totalAmount row 2 column 1 columnSpan 2Keep width, row and placement information in layout, where renderers read the form’s geometry. compose using computes a field value only; it does not position the field.
Submitting
Section titled “Submitting”on submit navigate to <Screen> [by <param>] runs after the form’s command succeeds. A bare by name can use a scalar response’s source name or a field name from a returns block. For example, RegisterInvoice in Invoicing declares returns invoiceId, and its form uses on submit navigate to InvoiceDetails by invoiceId without supplying an invoice identity field.
A block on submit has the same response scope: use with id from invoiceId on a navigation action, or a returned name in set … to, notify or confirm. Form fields keep their existing meaning if their names collide with response names. Nested execute success and failure branches follow the continuation value rules. Omit on submit and a successful submit simply leaves the user where they were.
This form scope is not added to a screen’s action … navigate … by … sugar. Compilers resolve the names; renderers must bind the actual values.
How references resolve
Section titled “How references resolve”for <Command>, populate via query <Query>, and on submit navigate to <Screen> follow the ordinary inside-out name resolution rules. A form sits at module level, so its location disambiguates by module, not by feature or slice. Unresolved and ambiguous references are warnings rather than errors because a name may still resolve to something outside the document.