Saving a form
Pick how a form saves (a save bar, a footer, nothing, or each field on its own) and what it sends to its submit route.
Two options decide how a Form saves. saveMode picks the controls: a save bar, footer buttons, none, or an instant save of each field. kind says what the form edits: a record that keeps its values, a new record to create, or an action that empties once sent. Together they cover a settings page, a table view's edit form, an invite dialog and a page of preferences that save as you go.
saveMode
saveMode | Renders |
|---|---|
bar (default) | A sticky save bar, shown while there are unsaved changes: it names the changed fields (or sections) and offers Discard and Save. See A form in a section. |
footer | The buttons in the form's footer. |
none | No buttons: something else reads or saves the form. |
instant | No buttons: each field the user changes saves on its own (Instant save). |
In a drawer or a modal, bar and footer both use the container's footer.
Footer states, live
The example below loads one of Helio's customers from a route of the docs site, which accepts a save and keeps nothing: a reload starts again from the same record. While the record is clean, the footer offers Cancel. Change the name: Discard and Save changes appear, and the field shows its previous value. Type fail as the name and save: the route refuses it on the Name field, the input keeps fail, and the footer stays. Correct the name and save again: the footer returns to Cancel and the Customer saved notification shows.
FormThe save bar on a page
The save bar stays within reach on a long form: it floats at the bottom of the visible area until the end of the form comes into view, then sits below the last field. The form makes room for it there so it does not cover the last field.
When hidden, the bar takes no space. When shown, its Cancel and "Unsaved changes" states (with Save, and Cancel or Discard) have the same height, so switching between them does not move the content.
Toasts never cover a save bar. While a save bar sits on the bottom edge of the screen (the floating bar on a page, or the footer of a form in a drawer), the toast stack rises above it so Discard and Save stay clickable, and moves back down once the bar hides. This works the same on desktop and on a phone.
kind
record(default). A record, a settings page, a table view's form. It keeps its values once saved. While clean it offers Cancel only when it has somewhere to go back to: the drawer or modal it sits in, the page of the app the user came from, orbackToon a page opened directly. Table views setbackToon their form pages, to the list.create. A form that makes a new record: a table view's add form, the duplicate it opens, a relation's add form. Its submit, Create unlesssubmitLabelnames it, shows from the start, so a duplicate saves as it opened, and neither the bar nor the fields list "changes", since all it holds is new; a read-only field still empty is left out (On a create form). It is declared, never guessed: a form posting tosubmitUrlis arecordunless it sayskind: "create", so a settings page posting the record it read keeps saving like one.action. A form that does something each time it is sent: send a message, invite someone, run a job. ItssubmitLabelbutton always shows in its footer, ready: a form pre-filled with valid defaults sends them as they are, and a form with no field to fill in is a submit button alone. Reset joins it once a value changes; in a drawer or a modal, Cancel stands there before that. After a successful submit each field goes back to the value it opened with: itsdefaultValue, or whatfetchUrlloaded.
static invite = Form({
submitUrl: "/api/invites",
submitUrlMethod: HttpMethod.post,
submitLabel: "$invite.send",
kind: "action",
fields: [/* … */],
});
A form on a page that sets neither option saves with the save bar, as a record. Declare kind: "create" on a form of your own that makes a new row, and kind: "action" on send, invite and run forms.
labelKey names the field of the loaded record whose value ends the page breadcrumb once the form has loaded ("… › Tasks › Write the docs"); table views fill it from their own labelKey.
An action response with a warning
The example below invites a colleague to Helio's workspace. Its route sends no email. Submit [email protected], who is already a member: the response invites no one and carries a warning, which the form shows instead of its success message. Any other address answers with a notice, shown as its own notification. Either way the action form empties its input after the submit.
FormWhat a submit sends
A form loaded from fetchUrl and submitted with a method other than POST updates a record, so it sends only the fields the user changed (plus submitDefaults): a value someone else saved in the meantime is not written back. A create form, and a form posting its loaded values as a new row (submitUrlMethod: HttpMethod.post, a duplicate), sends every field holding a value.
A field the user cleared is sent as null, or [] for a field holding a list (a multiple select, a tree, a relation, files), so that the route clears it. An emptied text counts as cleared, whatever the input (text, textarea, e-mail, URL, phone, rich text, number). A localized field is the exception: it is stored as one value per language, so it sends each emptied language as "", even when every language is emptied. A field that started empty and is still empty is not sent, and a disabled field is never cleared. A required field cleared is refused by the route, and its error shows under the field.
The route behind such a form reads the body as a partial update: an absent key means unchanged, null means cleared. A table view's edit route (TableViewRoutes.Edit) already does. A route of your own that expects the whole record has to merge the body into the stored row instead of replacing it.
Once such an update is saved, the form shows what the server stored rather than what was typed: a value the route normalizes (a VAT number stripped of its spaces, the empty rows of a list dropped) shows normalized at once, not after a reload. A route that answers the record, as a table view's edit route answers the stored row read as its get route reads it, is read without a second request; its answer holds the record when it carries one of the form's fields, and only those are taken. A route answering anything else ({ success: true }, nothing) has the form read the record again from fetchUrl; a change made while that read runs is kept, and a failed read leaves the values as they were sent. The form stays saved. A create form, an action form, a form with redirectOnSuccess and an instant save apply nothing.
Instant save
With saveMode: "instant", a form has no save bar and no footer: each field the user changes is validated alone, then sent alone, as a partial submit of that field to submitUrl, with submitDefaults, and no success toast. A cleared field goes as its empty value, null or [].
static preferences = Form({
fetchUrl: "/api/preferences",
submitUrl: "/api/preferences",
saveMode: "instant",
fields: [
{ id: "digest", label: "Daily digest", type: new DefaultDataTypes.BooleanType() },
{ id: "signature", label: "Signature", type: new DefaultDataTypes.StringType({ textarea: true }) },
],
});
- When a field saves. A pick (a select, a switch, a date, tags) saves at once. A typed field (a text, a number, an address, the rows of a repeater, code, a secret, a localized field) saves once typing pauses (500 ms). A change made while the same field is saving is sent once that save ends, so the last value always wins; a slow validation of an older value never queues a newer one. A text still waiting when the user leaves the page is saved.
- What the user sees. Each row shows its state: Saving, then Saved for two seconds, or Not saved with Retry. On a page, the header carries the "Saved instantly" pill, which reads "Saving" while a change is being written and turns red with "Not saved" while a save failed; a sectioned form also shows its state under its side list.
- When it fails. An invalid value is shown with its error, never sent. A save the server refuses puts back the value the server last confirmed, not the one the form opened with, then says why under the field (or in a toast), leaving the other fields' errors in place; Retry sends the change again.
- What it excludes. An
actionform ignoresinstantand saves with the bar. An instant form shows no "Changed · was X" field note, since nothing waits for a save.
Since it sends one field at a time, the submitUrl of an instant form must accept a partial body, as a table view's edit route does. The DMS's own Language & region page is such a form, and the notification preferences and Appearance pages save through the same mechanism.
A custom Vue page that saves as it goes shows the same pill with useInstantSaveHeader and DmsSaveStatus (Lists & settings).

