Skip to main content

Cancel and Submit Actions

Field is the forms page: labels, errors, help text, groups, and TanStack Form. Start there for anything inside one field. This recipe covers what goes around the fields: the buttons that end the form, and the sections above them.

Desktop viewport
Tablet viewport
Mobile viewport

Why a recipe, not a component

Each part already exists. Strata lays out the sections, Field wires each control to its label and errors, and Button submits. What joins them is your form: its state, its validation, and the request it sends. A Form component would have to own all three, so mantle leaves the <form> to you.

Sections

  • Put the <form> around Strata.Root and the actions row. The row then sits below the last section, inside the form, where the submit button needs to be.
  • Give each group of fields that needs its own sentence a Strata.Section. The Strata.Title names the group, and the Strata.Description says what its controls do.
  • Put one Field.Item per control in Strata.Body, and stack several in a Field.Group.
  • Give every control its own Field.Label. A Strata.Title is a heading, so it names the section and not the control (see Strata accessibility).
  • Skip Strata for a short form with one group. A Field.Group and the actions row below it are enough.

Actions

  • End the form with one actions row: Cancel, then the primary button, aligned to the end. The DOM order is the visual order, so the primary button sits on the right and gets focus last. Dialog.Footer and Sheet.Footer use the same order.
  • Make the primary button type="submit" with appearance="filled", and name it for what it does: Create endpoint, not Submit or OK.
  • Make Cancel type="button" in your app, and send the person back where they came from. With a router, compose <Button asChild> around its Link. The demo uses type="reset" because a preview frame has nowhere to go back to.
  • Set isLoading on the primary button while the request runs. It shows a spinner and blocks a second submit, and the label stays the same.
  • Disable the fields and Cancel while the request runs, so an edit can't land after the values went out. The demo composes Strata.Root onto a <fieldset disabled>, which disables every control inside it.
  • Let the browser check required and type="url" before your handler runs, and keep the primary button enabled, so a click shows the person what to fix. Show what the server rejects on the field it belongs to, with Field.Errors (see Field error messages).

Edit saved settings with a Sandbar

A settings page edits values that already saved. Leave the actions row out, and show a Sandbar while the form has unsaved changes. Its Save changes and Discard buttons replace the actions row, and it stays in view however long the page is.

  • Keep Sandbar.Root mounted, and set its open prop from whether the form differs from what saved.
  • Render it inside the form, or right after it, so Tab moves from the last field to its buttons.

The Sandbar page has the full form, a failed save, and how to block navigation while changes are unsaved.

Destructive actions

Keep Delete out of the actions row. Give it its own last section, as in the Strata danger zone example, and confirm it with an AlertDialog before it runs. Beside Save, a destructive button is one slip away from the wrong click.