Skip to content

<sessions-form>

Fields saved together, with the host’s Save.

Preact & React<Form>GroupFormsDrawn asForm

Preview

Drawn by the same renderers Sessions uses for your extension, from the DOM example beside it, without its event handlers.

When to use it

Set dirty while the form holds changes the viewer has not saved, and the host offers a Save for it: on a staff page, the page’s own Save — in its header, or the bottom bar on a phone — which saves every dirty form on the page at once; anywhere else, a compact Save at the form’s foot. Draw no Save of your own. The Save stays loading until the submit handler’s promise settles. To report a failure, throw an Error with a message the viewer can read: the host shows it and the form stays dirty. Clear dirty once the save lands. Enter in a single-line field also submits; a form with no dirty can still carry its own sessions-button type="submit" (a field’s accessory, say).

In Preact and React, import the component of the same name from @sessions/apps/preact or @sessions/apps/react. Attributes become camelCase props, a boolean attribute is a boolean prop, and an event is an on prop that receives the event’s detail.

Attributes

Attribute
dirtyboolean
The form holds unsaved changes: the host shows a Save for it until it is cleared.Prop dirty

Events

submitdetail: undefined
The form was submitted. Return a promise to keep the Save loading; throw to report a failure.Prop onSubmit
Example
import {Form, TextField} from '@sessions/apps/preact';

<Form dirty={model.draft != null} onSubmit={() => model.save()}>
  <TextField
    label="Staff note"
    multiline
    value={model.draft ?? model.note}
    onInput={(value) => model.setDraft(value)}
  />
</Form>

In the same group