Skip to content
Star

Forms

Label fields, show validation errors, and save a form.

See Build a form people can complete for labels, error messages, and keyboard use.

Choose how to validate

For a small form, use Form with Base UI validation. Field connects a control to its label, help text, and error. Field.Control renders Ghost Input.

Add TanStack Form when you need typed values, coordinated validation, or subscriptions to form state.

Connect TanStack Form

Install Ghost UI and its component styles, then add TanStack Form.

Install dependencies

Render ProjectForm with a save function that resolves after saving and rejects on failure. Submit with a blank name to see the field error. Then enter a name and save.

project-form.tsx

TanStack Form runs validation and submission. The example uses noValidate and onSubmitCapture so native and Base UI validation stay out of that submission flow. Pass the TanStack error to Field.Error match, and set invalid from the same state so the control and error stay linked.

Validate and save

Return a message from the validator when the input is invalid, or undefined when it passes. Validate again on the server. For schema or async validation, see TanStack validation. Convert error objects to readable messages before rendering them.

Keep the entered values if a save fails. Disable repeat submissions while a save is pending. If the server returns a field error, show it beside the field and decide when to clear or revalidate it.

Compose and extend

Use form.Subscribe to update the submit button as saving starts or ends. Connect custom controls through their own value and blur callbacks. Keep field components stable so typing preserves focus.

Use Fieldset to name a related group. Labels, layout and styling remain on the component pages. For exact hooks, types, field paths, arrays and reset behavior, use TanStack Form; for Ghost props, use Form API and Field API.

Troubleshooting

  • Submit does nothing. Check that the capture handler calls handleSubmit and that only one validator controls submission.
  • Typing leaves the value unchanged. Pass the current value and its change callback.
  • An error stays hidden. Read invalid and Field.Error match from the same state.
  • A different record shows old values. Reset the form explicitly when switching records and protect unsaved input from late fetches.