Skip to content
Ballpoint

Form

A form that validates itself: fields report to it, it focuses the first that fails and hands you the values. No form library.

From shadcn/ui
Built on Base UI Form

This is how you appear on the page.

Installation

pnpm dlx shadcn@latest add @ballpoint/form

Usage

tsx
import { Form, FormDescription, FormField, FormLabel, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"

<Form onFormSubmit={(values) => save(values)}>
  <FormField name="email">
    <FormLabel>Email</FormLabel>
    <Input type="email" required />
    <FormMessage match="valueMissing">We need somewhere to write to.</FormMessage>
  </FormField>
</Form>

Examples

Errors from the server

Pass errors keyed by field name; they clear when the field is edited.

API reference

Form onFormSubmit
(values, details) => void

Called with every field's value, keyed by name, once they all validate.

Form errors
Record<string, string | string[]>

Errors from outside (a server), keyed by the field's name.

Form validationMode
default "onSubmit"
"onSubmit" | "onBlur" | "onChange"

When fields are first checked.

FormField name / validate
string / (value) => string | null

The field's key in the values, and a check of your own.

FormMessage match
string | boolean

Show only for one kind of failure, such as "valueMissing" or "typeMismatch".

Every other prop goes to Base UI's Form.