Form
Collects values for one model and saves them with an insert or update operation.
Use it for: Creating and editing records. Its inputs bind to the fields of the form’s model.
- CategoryData
- ChildrenAny number
- DataNone
- ActionOn save: run an insert or update operation
| Prop | Required | Accepts | What it does |
|---|---|---|---|
model |
Yes | text in a fixed format | The model this form edits. |
submitLabel |
Yes | text, up to 200 characters | The label of the save button. |
Every component also accepts id (required, unique on its screen), and the optional preset and style described in Style options.
Example
Section titled “Example”From the fitness example project:
{ "id": "workout-form", "type": "Form", "props": { "model": "workout", "submitLabel": "Save workout" }, "children": [ { "id": "identity", "type": "Text", "props": {}, "bindings": { "value": { "model": "workout", "field": "id" } } }, { "id": "name", "type": "Input", "props": { "label": "Workout name", "inputType": "text", "required": true }, "bindings": { "value": { "model": "workout", "field": "name" } } }, { "id": "duration", "type": "Input", "props": { "label": "Minutes", "inputType": "number", "required": true }, "bindings": { "value": { "model": "workout", "field": "duration" } } }, { "id": "category", "type": "Select", "props": { "label": "Category", "required": true, "options": [ { "label": "Strength", "value": "strength" }, { "label": "Cardio", "value": "cardio" }, { "label": "Mobility", "value": "mobility" } ] }, "bindings": { "value": { "model": "workout", "field": "category" } } }, { "id": "completed", "type": "Switch", "props": { "label": "Completed", "required": true }, "bindings": { "value": { "model": "workout", "field": "completed" } } }, { "id": "date", "type": "DatePicker", "props": { "label": "Workout date", "required": true }, "bindings": { "value": { "model": "workout", "field": "date" } } }, { "id": "notes", "type": "TextArea", "props": { "label": "Notes", "maxLength": 1000 }, "bindings": { "value": { "model": "workout", "field": "notes" } } } ], "action": { "type": "operation", "operationId": "update-workout", "parameters": { "id": { "source": "field", "model": "workout", "field": "id" }, "name": { "source": "field", "model": "workout", "field": "name" }, "duration": { "source": "field", "model": "workout", "field": "duration" }, "completed": { "source": "field", "model": "workout", "field": "completed" }, "date": { "source": "field", "model": "workout", "field": "date" }, "notes": { "source": "field", "model": "workout", "field": "notes" }, "category": { "source": "field", "model": "workout", "field": "category" } } }, "form": { "mode": "edit", "initialData": { "type": "operation", "operationId": "get-workout", "parameters": { "id": { "source": "route", "parameter": "id" } } }, "lifecycle": { "validation": "submit", "concurrency": "single-flight", "retry": "manual", "success": "stay", "failure": "preserve-values" } }}