Interface FieldOptions<T, K>

Options for every field. See each property for more information.

Type Parameters

  • T

  • K extends keyof T = keyof T

Hierarchy

  • FieldOptions

Properties

errorMessages?: Partial<ErrorStrings>

Map of custom error messages for the default validation methods.

See

maxLength?: number

Maximum length (in characters) for the field.

This will cause the form to be invalid if the field is longer than the given length, and an error message will be provided in UseFormReturn.errors.

To provide a custom error message, use errorMessages.

minLength?: number

Minimum length (in characters) for the field.

This will cause the form to be invalid if the field is shorter than the given length, and an error message will be provided in UseFormReturn.errors.

To provide a custom error message, use errorMessages.

multiple?: boolean

If true, handlers will treat the field as an array and not a single value.

If you supply an array as the initial value, this will be set to true automatically.

pattern?: string | RegExp

A regular expression that the field must match.

This will cause the input to not update if the value does not match the given pattern. To cause a validation error for a pattern, use validate instead.

required?: boolean

If true, the field will be required.

This will cause the form to be invalid if the field is empty and an error message will be provided in UseFormReturn.errors.

To provide a custom error message, use errorMessages.

validate?: Validator<T[K]>

A custom validation function for the field.

If it returns an empty string, null or undefined, the field is valid.

Otherwise, the field is invalid and the returned string will be the error message.

Param

The value of the field.

Returns

The error message, if any, or undefined/null if the field is valid.

See

Methods

  • A callback for leaving focus from the input, which also contains the parsed value.

    Never use onBlur on the input field directly, or it will break validation for onBlur.

    Use this callback instead, which acts right after the input's onBlur callback.

    Parameters

    • event: ChangeEvent

      The input change event.

    • value: T[K]

      The parsed value of the field.

    Returns void

  • A callback for changing the input, which also contains the parsed value.

    Never use onChange on the input field directly, or it will not work to update the form state.

    Use this callback instead, which acts right after the input's onChange callback.

    Parameters

    • event: ChangeEvent

      The input change event.

    • value: T[K]

      The parsed value of the field.

    Returns void

  • Parse the value of the field before it is set in the form state.

    Returns

    The parsed value.

    See

    • state for the parsed form state
    • rawState for the raw form state

    Parameters

    • value: any

      The value of the field.

    Returns T[K]

Generated using TypeDoc