Component reference
FormError
Field-level validation and server feedback connected to Form state.
Connect validation and server errors
FormError reads a field message from Form. Use validation, setError and clearErrors to manage its content, and named-part classes to customize its presentation.
FormError — show and customize field feedback
FormError reads errors[name] from its parent Form. Its required name must match the registered field key. It renders a role=alert paragraph only when that field has a message; register connects the field's aria-describedby and aria-invalid attributes to it.
Return messages from validate or call form.setError(name, message) for a server response. Editing a registered field clears its error; clearErrors removes the message explicitly. Use className or classNames.error to style the message while preserving its association and alert role.
"use client";
import { Button, Form, FormError, FormSubmit, Input, useForm } from "@pimolu/react";
export function FieldError() {
const form = useForm({
defaultValues: { name: "" },
validate: (values) => values.name.trim() ? {} : { name: "Enter your name." },
});
return (
<Form form={form} autoComplete="off" className="grid gap-4">
<Input label="Name" {...form.register("name")} />
<FormError name="name" classNames={{ error: "profile-error" }} />
<div className="flex flex-wrap gap-3">
<FormSubmit>Validate</FormSubmit>
<Button
onClick={() => form.setError(
"name",
"This name is already used (simulated server response)."
)}
>
Simulate server error
</Button>
<Button appearance="ghost" onClick={() => form.clearErrors("name")}>Clear error</Button>
</div>
<style>
{
`.profile-error {
font-weight: 600;
border-inline-start: 3px solid currentColor;
padding-inline-start: 12px;
}`
}
</style>
</Form>
);
}New to Pimolu? Follow the Quick start or the Next.js guide for the shared stylesheet and application provider.
Preview
Live previewOptional six-digit hex. Clear to restore the preset. Check contrast with your brand color.
Changes apply to this preview only.
Loading the interactive example?
Width adapts to the available space
"use client";
import { useState } from "react";
import { Form, FormError, FormSubmit, Input, useForm } from "@pimolu/react";
export function FormErrorExample() {
const [message, setMessage] = useState("");
const form = useForm({
defaultValues: { name: "" },
validate: (values) => values.name.trim() ? {} : { name: "Enter your name." },
onSubmit: (values) => setMessage("Validated: " + values.name),
});
return (
<Form form={form} autoComplete="off" className="grid gap-4">
<Input label="Name" {...form.register("name")} />
<FormError name="name" />
<FormSubmit>Validate profile</FormSubmit>
<p role="status">{message}</p>
</Form>
);
}More examples
Different configurations and compositions using the real Pimolu API. Each preview runs independently and follows the site appearance.
Validate on blur
Choose when to set a field message and clear it on editing.
Styled Select integration
Connect a control using onValueChange with explicit ARIA associations.
Named-part customization
Style the error slot while preserving its alert role and field association.
Usage
Place FormError inside Form with a name matching a field key. It reads form.errors[name] and renders nothing when there is no message. Return an error map from validate or call form.setError(name, message) after a server response.
Spread form.register(name) onto a native-event input such as Input. Registration connects aria-invalid and aria-describedby to the message. For controls exposing onValueChange, connect form.values, setValue and those ARIA attributes explicitly.
Editing a registered field or calling setValue clears its error. clearErrors(name) removes one error; clearErrors() removes all. FormError only renders feedback: it does not run validation or submit the form.
Customize the message with className or classNames.error, or provide Form-level classNames.error for shared styling. Preserve the generated id and alert role. The current API displays a text message; it does not accept arbitrary children or Button props.
API reference
Generated from the public TypeScript declarations. Native HTML attributes are inherited where the component extends them; this reference includes Pimolu props and selected common native attributes.
PimoluFormErrorProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
classNames | PimoluClassNames<"form"> | undefined | — | Additive classes for stable named parts, including composed descendants. Parts: endIcon, error, label, root, spinner, startIcon, submit. Parts render only when the corresponding component or state is present. |
nameRequired | string | — | Registered field name. |
className | string | undefined | — | Public Pimolu prop; see the source declaration for details. |
classNamesPimoluClassNames<"form"> | undefinedNo default extracted.
Additive classes for stable named parts, including composed descendants. Parts: endIcon, error, label, root, spinner, startIcon, submit. Parts render only when the corresponding component or state is present.
nameRequiredstringNo default extracted.
Registered field name.
classNamestring | undefinedNo default extracted.
Public Pimolu prop; see the source declaration for details.
Accessibility
- Keep the error next to its field and explain how to correct it. The message is a paragraph with role=alert and a stable id associated with the registered control.
- Do not rely on color alone. Validation does not automatically focus the first invalid field; decide how your application should handle focus and an error summary.