# Creating and editing

A form that adds or changes a record: where it opens, its fields, saving, and leaving with unsaved edits.

## When it applies

- Someone adds a record or changes its details in a form.
- A long form, or a record read beside the page, opens in a Drawer. A short task that holds the page until it is done opens in a Dialog.

## Components

- [Drawer](../components/drawer.md): The panel a long form opens in.
- [Dialog](../components/dialog.md): A short edit, and the Discard changes? question.
- [Field](../components/field.md): Every control's label, hint and error.
- [Input](../components/input.md): One line of text.
- [Textarea](../components/textarea.md): Several lines, like a note.
- [Select](../components/select.md): One value from a list a person can scan.
- [Date Input](../components/date-input.md): A date known by heart, like a date of birth.
- [Date Picker](../components/date-picker.md): A date near today, like a due date.
- [Toast](../components/toast.md): Confirms the save.

## Rules

- Do: Wrap every form control in a `Field`, so the label names it and the error is announced.
- Do: Use `DateInput` for a date people know by heart or read off a document, with `max` set to today when it can't be in the future. Use `DatePicker` for a date near today.
- Do: Set `dismissible={false}` on the drawer while it holds unsaved edits, and ask Discard changes? in `onDismissAttempt`.
- Do: Confirm the save with `toast`, with a title that says what happened, like "Record saved".
- Do: Start a control with `defaultValue`, or hold it with `value` and `onValueChange`. Never both.
- Don't: Use a `Select` for two or three options a person compares, like Yes or No. Use `RadioGroup` or `SegmentedControl`.
- Don't: Use a `Dialog` for a long form or a whole record. Use `Drawer`, the CRM's side panel.
- Don't: Use a placeholder in place of a label. Every control has a label, or an `aria-label` where there is no visible text.

## See it

- [Form panel](../screens/example-form-panel.md): A form in a panel over the list: fields in one column, pairs side by side, and Cancel and Save in the panel's footer.
