# @salmonui/inputs/form API reference

> 19 exported symbols of @salmonui/inputs/form: 4 components, 1 function, 8 interfaces and 6 types.

Canonical: https://salmonui.dev/docs/reference/inputs/form

```ts
import { … } from '@salmonui/inputs/form';
```

## Components

### Field

Kind: component

Page: https://salmonui.dev/docs/reference/inputs/form/Field

```ts
function Field(props: FieldProps): ReactNode;
```

Label, description, error and validation around a custom control.
Every Salmon field renders the same parts itself.

Props: [`FieldProps`](https://salmonui.dev/docs/reference/inputs/form/FieldProps) (its members are the props)

### FieldDescription

Kind: component

Page: https://salmonui.dev/docs/reference/inputs/form/FieldDescription

```ts
function FieldDescription({ children, className, style }: {
    readonly children?: ReactNode;
    readonly className?: string;
    readonly style?: CSSProperties;
}): ReactNode;
```

The description part for custom layouts.

### FieldError

Kind: component

Page: https://salmonui.dev/docs/reference/inputs/form/FieldError

```ts
function FieldError({ children, className, style }: {
    readonly children?: ReactNode;
    readonly className?: string;
    readonly style?: CSSProperties;
}): ReactNode;
```

The error part for custom layouts: renders the enclosing field's
error (or `children`) with the id its control points at.

### Form

Kind: component

Page: https://salmonui.dev/docs/reference/inputs/form/Form

```ts
function Form(props: FormProps): ReactNode;
```

A native `<form>` that validates its Salmon fields on submit. Native submission, `FormData`, `useFormStatus` and React 19
actions work unchanged. `ref` is the `<form>`.

Props: [`FormProps`](https://salmonui.dev/docs/reference/inputs/form/FormProps) (its members are the props)

## Functions

### useFieldContext

Kind: function

Page: https://salmonui.dev/docs/reference/inputs/form/useFieldContext

```ts
function useFieldContext(): FieldState | null;
```

The state of the enclosing `Field`, or null outside one.

## Interfaces

### FieldCommonProps

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/form/FieldCommonProps

```ts
interface FieldCommonProps {
    readonly label?: ReactNode;
    readonly description?: ReactNode;
    readonly errorMessage?: ReactNode | ((ctx: {
        readonly errors: readonly string[];
    }) => ReactNode);
    readonly invalid?: boolean | undefined;
    readonly validation?: FieldValidation | undefined;
    readonly validateOn?: ValidateOn | undefined;
    readonly size?: FieldSize | undefined;
}
```

Props every Salmon field shares.

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `label` | `readonly label?: ReactNode;` | optional |  |
| `description` | `readonly description?: ReactNode;` | optional |  |
| `errorMessage` | `readonly errorMessage?: ReactNode \| ((ctx: {     readonly errors: readonly string[]; }) => ReactNode);` | optional | Error text (or a function of the errors) shown while the field is invalid. |
| `invalid` | `readonly invalid?: boolean \| undefined;` | optional | Forces the error state. |
| `validation` | `readonly validation?: FieldValidation \| undefined;` | optional | Rules in the Data Grid vocabulary. |
| `validateOn` | `readonly validateOn?: ValidateOn \| undefined;` | optional | When errors appear; default the `Form`'s, else `'blur'`. |
| `size` | `readonly size?: FieldSize \| undefined;` | optional | Metric set. Default `'md'`. |

### FieldProps

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/form/FieldProps

```ts
interface FieldProps extends FieldCommonProps {
    readonly children: (field: FieldRenderProps) => ReactNode;
    readonly name?: string | undefined;
    readonly errorPlacement?: 'auto' | 'manual' | undefined;
    readonly id?: string | undefined;
    readonly value?: unknown;
    readonly required?: boolean | undefined;
    readonly requiredMark?: boolean | undefined;
    readonly disabled?: boolean | undefined;
    readonly localeText?: FieldValidationText | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
}
```

Members (18):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `children` | `readonly children: (field: FieldRenderProps) => ReactNode;` |  |  |
| `name` | `readonly name?: string \| undefined;` | optional |  |
| `errorPlacement` | `readonly errorPlacement?: 'auto' \| 'manual' \| undefined;` | optional | `'manual'` when the children render `FieldError` themselves. Default `'auto'`. |
| `id` | `readonly id?: string \| undefined;` | optional | Id of the control (default from `useId`); the label points at it. |
| `value` | `readonly value?: unknown;` | optional | The control's current value, for `validation` rules. |
| `required` | `readonly required?: boolean \| undefined;` | optional |  |
| `requiredMark` | `readonly requiredMark?: boolean \| undefined;` | optional | `true` marks the label while the control is required (as `Form requiredMark` does); `false` opts out under a marking `Form`. |
| `disabled` | `readonly disabled?: boolean \| undefined;` | optional |  |
| `localeText` | `readonly localeText?: FieldValidationText \| undefined;` | optional |  |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |
| `label` | `label?: ReactNode;` | optional, inherited |  |
| `description` | `description?: ReactNode;` | optional, inherited |  |
| `errorMessage` | `errorMessage?: ((ctx: { readonly errors: readonly string[]; }) => ReactNode) \| ReactNode;` | optional, inherited | Error text (or a function of the errors) shown while the field is invalid. |
| `invalid` | `invalid?: boolean;` | optional, inherited | Forces the error state. |
| `validation` | `validation?: FieldValidation;` | optional, inherited | Rules in the Data Grid vocabulary. |
| `validateOn` | `validateOn?: ValidateOn;` | optional, inherited | When errors appear; default the `Form`'s, else `'blur'`. |
| `size` | `size?: FieldSize;` | optional, inherited | Metric set. Default `'md'`. |

### FieldRenderProps

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/form/FieldRenderProps

```ts
interface FieldRenderProps {
    readonly inputProps: {
        readonly id: string;
        readonly name: string | undefined;
        readonly required: boolean | undefined;
        readonly disabled: boolean | undefined;
        readonly 'aria-describedby': string | undefined;
        readonly 'aria-invalid': true | undefined;
        readonly 'aria-errormessage': string | undefined;
        readonly ref: (el: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null) => void;
        readonly onBlur: () => void;
    };
    readonly errors: readonly string[];
    readonly invalid: boolean;
    readonly validating: boolean;
}
```

What a custom control receives from `Field`.

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `inputProps` | `readonly inputProps: {     readonly id: string;     readonly name: string \| undefined;     readonly required: boolean \| undefined;     readonly disabled: boolean \| undefined;     readonly 'aria-describedby': string \| undefined;     readonly 'aria-invalid': true \| undefined;     readonly 'aria-errormessage': string \| undefined;     readonly ref: (el: HTMLInputElement \| HTMLTextAreaElement \| HTMLSelectElement \| null) => void;     readonly onBlur: () => void; };` |  | Spread on the native element that carries the value: `id`, `name`, ARIA wiring, `ref`, `onBlur`. |
| `errors` | `readonly errors: readonly string[];` |  |  |
| `invalid` | `readonly invalid: boolean;` |  |  |
| `validating` | `readonly validating: boolean;` |  |  |

### FieldState

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/form/FieldState

```ts
interface FieldState {
    readonly inputId: string;
    readonly labelId: string;
    readonly descriptionId: string;
    readonly errorId: string;
    readonly errors: readonly string[];
    readonly invalid: boolean;
    readonly validating: boolean;
    readonly hasDescription: boolean;
    readonly inputProps: {
        readonly id: string;
        readonly 'aria-describedby': string | undefined;
        readonly 'aria-invalid': true | undefined;
        readonly 'aria-errormessage': string | undefined;
    };
    readonly rootProps: {
        readonly 'data-invalid': '' | undefined;
        readonly 'data-disabled': '' | undefined;
        readonly 'data-validating': '' | undefined;
    };
    readonly onBlur: () => void;
    readonly validate: () => readonly string[] | Promise<readonly string[]>;
    readonly errorMessage: ReactNode | ((ctx: {
        readonly errors: readonly string[];
    }) => ReactNode) | undefined;
}
```

Members (13):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `inputId` | `readonly inputId: string;` |  |  |
| `labelId` | `readonly labelId: string;` |  |  |
| `descriptionId` | `readonly descriptionId: string;` |  |  |
| `errorId` | `readonly errorId: string;` |  |  |
| `errors` | `readonly errors: readonly string[];` |  | Errors currently shown (rules, native constraints, server). |
| `invalid` | `readonly invalid: boolean;` |  | True while an error is shown or `invalid` is set. |
| `validating` | `readonly validating: boolean;` |  |  |
| `hasDescription` | `readonly hasDescription: boolean;` |  |  |
| `inputProps` | `readonly inputProps: {     readonly id: string;     readonly 'aria-describedby': string \| undefined;     readonly 'aria-invalid': true \| undefined;     readonly 'aria-errormessage': string \| undefined; };` |  | ARIA wiring for the element that owns the value. |
| `rootProps` | `readonly rootProps: {     readonly 'data-invalid': '' \| undefined;     readonly 'data-disabled': '' \| undefined;     readonly 'data-validating': '' \| undefined; };` |  | `data-*` state hooks for the root. |
| `onBlur` | `readonly onBlur: () => void;` |  | Call from the control's blur handler. |
| `validate` | `readonly validate: () => readonly string[] \| Promise<readonly string[]>;` |  | Runs every rule now and reveals the result (e.g. on commit). |
| `errorMessage` | `readonly errorMessage: ReactNode \| ((ctx: {     readonly errors: readonly string[]; }) => ReactNode) \| undefined;` |  |  |

### FieldValidatorContext

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/form/FieldValidatorContext

```ts
interface FieldValidatorContext {
    readonly name: string;
    readonly formData: FormDataLike | null;
    readonly isNew: false;
}
```

Context of a form field's custom validators (`@salmonui/inputs/form` `Field`). It is passed as both the `row` and the
`ctx` argument, so `validate(value, { formData })` reads other fields.

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `name` | `readonly name: string;` |  | The field's `name` (`''` without one). |
| `formData` | `readonly formData: FormDataLike \| null;` |  | The owning form's data at validation time; `null` outside a form. |
| `isNew` | `readonly isNew: false;` |  |  |

### FormProps

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/form/FormProps

```ts
interface FormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, 'action'> {
    readonly children?: ReactNode;
    readonly ref?: Ref<HTMLFormElement> | undefined;
    readonly action?: string | ((formData: FormData) => void | Promise<void>) | undefined;
    readonly validationBehavior?: ValidationBehavior | undefined;
    readonly validateOn?: ValidateOn | undefined;
    readonly validationErrors?: ValidationErrors | undefined;
    readonly onBeforeValidate?: ((event: FormValidateEvent) => void) | undefined;
    readonly onValidate?: ((result: FormValidationResult) => void) | undefined;
    readonly requiredMark?: boolean | undefined;
}
```

Members (9):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `children` | `readonly children?: ReactNode;` | optional |  |
| `ref` | `readonly ref?: Ref<HTMLFormElement> \| undefined;` | optional |  |
| `action` | `readonly action?: string \| ((formData: FormData) => void \| Promise<void>) \| undefined;` | optional | A URL or a React 19 action (`useActionState`). |
| `validationBehavior` | `readonly validationBehavior?: ValidationBehavior \| undefined;` | optional | `'native'` (default) blocks an invalid submit and focuses the first invalid field; `'aria'` marks fields and submits. |
| `validateOn` | `readonly validateOn?: ValidateOn \| undefined;` | optional | Default `validateOn` of the fields inside. Default `'blur'`. |
| `validationErrors` | `readonly validationErrors?: ValidationErrors \| undefined;` | optional | Server errors keyed by field `name`, shown until the field's value changes. |
| `onBeforeValidate` | `readonly onBeforeValidate?: ((event: FormValidateEvent) => void) \| undefined;` | optional |  |
| `onValidate` | `readonly onValidate?: ((result: FormValidationResult) => void) \| undefined;` | optional |  |
| `requiredMark` | `readonly requiredMark?: boolean \| undefined;` | optional | Marks the label of every required field inside with a decorative asterisk (`@salmonui/inputs/form/styles.css`); the requirement itself is announced from `required` / `aria-required`. A `Field` opts out with `requiredMark={false}`. |

### FormValidateEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/form/FormValidateEvent

```ts
interface FormValidateEvent {
    readonly form: HTMLFormElement;
    readonly defaultPrevented: boolean;
    preventDefault(): void;
}
```

`onBeforeValidate` event: `preventDefault()` skips client validation for this submit.

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `form` | `readonly form: HTMLFormElement;` |  |  |
| `defaultPrevented` | `readonly defaultPrevented: boolean;` |  |  |
| `preventDefault` | `preventDefault(): void;` |  |  |

### FormValidationResult

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/form/FormValidationResult

```ts
interface FormValidationResult {
    readonly valid: boolean;
    readonly errors: Readonly<Record<string, readonly string[]>>;
}
```

`onValidate` result: errors keyed by field `name`.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `valid` | `readonly valid: boolean;` |  |  |
| `errors` | `readonly errors: Readonly<Record<string, readonly string[]>>;` |  |  |

## Types

### FieldSize

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/form/FieldSize

```ts
type FieldSize = 'sm' | 'md' | 'lg';
```

Field size (a fixed metric set, not density).

### FieldValidation

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/form/FieldValidation

```ts
type FieldValidation = ColumnValidation<FieldValidatorContext, FieldValidatorContext>;
```

Rules of a form field: the column vocabulary with the field context.

Members (18):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `required` | `required?: RuleValue<boolean>;` | optional, inherited |  |
| `min` | `min?: RuleValue<string \| number>;` | optional, inherited |  |
| `max` | `max?: RuleValue<string \| number>;` | optional, inherited |  |
| `range` | `range?: RuleValue<readonly [string \| number, string \| number]>;` | optional, inherited |  |
| `minLength` | `minLength?: RuleValue<number>;` | optional, inherited |  |
| `maxLength` | `maxLength?: RuleValue<number>;` | optional, inherited |  |
| `rangeLength` | `rangeLength?: RuleValue<readonly [number, number]>;` | optional, inherited |  |
| `number` | `number?: RuleValue<boolean>;` | optional, inherited |  |
| `digits` | `digits?: RuleValue<boolean>;` | optional, inherited |  |
| `email` | `email?: RuleValue<boolean>;` | optional, inherited |  |
| `url` | `url?: RuleValue<boolean>;` | optional, inherited |  |
| `date` | `date?: RuleValue<boolean>;` | optional, inherited |  |
| `dateIso` | `dateIso?: RuleValue<boolean>;` | optional, inherited |  |
| `creditcard` | `creditcard?: RuleValue<boolean>;` | optional, inherited |  |
| `tel` | `tel?: RuleValue<boolean>;` | optional, inherited |  |
| `pattern` | `pattern?: RuleValue<string \| RegExp>;` | optional, inherited | A pattern string or a RegExp, tested as a search: a partial match passes, so anchor the pattern (`^[A-Z]{3}$`) to require the whole value. |
| `validate` | `validate?: CustomValidator<FieldValidatorContext, FieldValidatorContext> \| readonly CustomValidator<FieldValidatorContext, FieldValidatorContext>[] \| readonly [...];` | optional, inherited | One custom validator, `[validator, message]`, or several. |
| `messages` | `messages?: Partial<ValidationMessages>;` | optional, inherited | Message overrides of this column, keyed by rule name; they win over `edit.messages`. |

### FieldValidationText

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/form/FieldValidationText

```ts
type FieldValidationText = {
    readonly [K in keyof ValidationMessages as `validation${Capitalize<K & string>}`]?: string;
};
```

Validation strings, flat keys shared with the Data Grid `localeText`
(`validationRequired`, `validationMin`, ...; `{0}` / `{1}` are the rule
arguments).

Members (17):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `validationCreditcard` | `validationCreditcard?: string;` | optional, inherited |  |
| `validationDate` | `validationDate?: string;` | optional, inherited |  |
| `validationDateIso` | `validationDateIso?: string;` | optional, inherited |  |
| `validationDigits` | `validationDigits?: string;` | optional, inherited |  |
| `validationEmail` | `validationEmail?: string;` | optional, inherited |  |
| `validationMax` | `validationMax?: string;` | optional, inherited |  |
| `validationMaxLength` | `validationMaxLength?: string;` | optional, inherited |  |
| `validationMin` | `validationMin?: string;` | optional, inherited |  |
| `validationMinLength` | `validationMinLength?: string;` | optional, inherited |  |
| `validationNumber` | `validationNumber?: string;` | optional, inherited |  |
| `validationPattern` | `validationPattern?: string;` | optional, inherited |  |
| `validationRange` | `validationRange?: string;` | optional, inherited |  |
| `validationRangeLength` | `validationRangeLength?: string;` | optional, inherited |  |
| `validationRequired` | `validationRequired?: string;` | optional, inherited |  |
| `validationTel` | `validationTel?: string;` | optional, inherited |  |
| `validationUrl` | `validationUrl?: string;` | optional, inherited |  |
| `validationValidate` | `validationValidate?: string;` | optional, inherited |  |

### ValidateOn

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/form/ValidateOn

```ts
type ValidateOn = 'blur' | 'change' | 'submit';
```

When errors become visible.

### ValidationBehavior

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/form/ValidationBehavior

```ts
type ValidationBehavior = 'native' | 'aria';
```

`'native'` blocks an invalid submit; `'aria'` marks fields and lets it proceed.

### ValidationErrors

Kind: type

Page: https://salmonui.dev/docs/reference/inputs/form/ValidationErrors

```ts
type ValidationErrors = Readonly<Record<string, string | readonly string[] | undefined>>;
```

Server errors keyed by field `name`.
