Skip to content

Forms

Two rules hold for every form in the app: when Save can be pressed, and what the unsaved changes dialog offers when the user leaves a form with edits.

When Save can be pressed

Save (the submit button) is disabled while any of these is true:

CaseWhy
A field has an errorThe error shows next to the field, so the user sees what to fix. Save waits until it is fixed.
Nothing changed (edit forms only)There is nothing to save. A create form has no “unchanged” state.
A save is runningThe button shows a spinner. A second press cannot send a second save.

Show the field error as text under the field (the error prop of Input), not as a toast. A toast is for a save that the server or the database refused.

<Button
type="submit"
disabled={!!nameError || !isDirty || isPending}
isLoading={isPending}
>
{t('common.save')}
</Button>

The unsaved changes dialog

When the user leaves a form that has edits (a tab, Back, or another location’s page), the app asks first. The dialog has three buttons, in this order:

ButtonVariantWhat it does
Cancelneutral-outlineCloses the dialog. The user stays, and the edits stay.
Discarddestructive-outlineLeaves without saving. The edits are lost.
SaveprimarySaves, then goes where the user was going.
  • Save is the one solid button, on the right. Discard is outline, because it sits next to a solid button. It uses the destructive color, because it loses the edits and cannot be undone.
  • Save follows the first rule. It is disabled while a field has an error or a save is running.
  • Save runs the same save as the page’s own Save button. It goes where the user pressed, not to the place the page’s own Save goes after a save.
  • While the save runs, Save shows a spinner, every button is disabled, and the dialog stays open.
  • If the save fails, the usual error toast shows and the dialog stays open. The user can try again, Discard, or Cancel.
  • If the save needs to ask something first (the item page’s converted amounts dialog), that dialog opens on top of this one. Confirm saves and then leaves. Cancel closes only the top dialog, and this one shows again.

In code, use the shared UnsavedChangesDialog (apps/web/src/components/shared/UnsavedChangesDialog). Do not build a new copy.


Section headings

A heading that folds is a left-aligned accordion trigger. A heading that does not fold is centered, with a line on each side.

HeadingLooks likeExampleIn code
folds (opens and closes)left-aligned, with a chevronthe quick edit dialog’s Stock settingsAccordion and AccordionTrigger
does not foldcentered, text-sm font-medium uppercase, a line on the left and the rightthe item Info tab’s Stock Settings, the bulk edit dialog’s three sections, the Add Item dialogSectionHeading
  • Never mix the two at one level of a form. A reader cannot tell which headings open.
  • SectionHeading is an h3 by default. Use as="h2" on a page whose title is the h1, and keep h3 inside a dialog.
  • Pass the spacing with className: pt-2 in item forms, my-2 in lists of choices.
import { SectionHeading } from '@/components/shared/SectionHeading'
<SectionHeading as="h2" className="pt-2">
{t('items.form.stockSettingsHeading')}
</SectionHeading>