Form Validation
GitHubHelpers that extract field-level and form-level messages from next-safe-action validation results.
Installation
bash
pnpm dlx shadcn@latest add @cs/form-validationUsage
tsx
import { getFormErrors, getValidationErrors } from "@/lib/cs/form-validation";tsx
const emailErrors = getValidationErrors("email", result.validationErrors);
const formErrors = getFormErrors(result.validationErrors);API Reference
getValidationErrors
Returns validation messages for one field, or null when the field is valid.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name * | string | - | - |
| validationErrors * | unknown | undefined | - | - |
Returns: unknown
getFormErrors
Returns form-level validation messages that do not belong to a field.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| validationErrors * | unknown | undefined | - | - |
Returns: unknown