Spec-Zone.ru › Valibot

forward

Forwards the issues of the passed validation action.

const Action = v.forward<TInput, TIssue, TPath>(action, path);

Generics

  • TInput extends Record<string, unknown> | ArrayLike<unknown>
  • TIssue extends BaseIssue<unknown>
  • TPath extends RequiredPath

Parameters

  • action BaseValidation<TInput, TInput, TIssue>
  • path ValidPath<TInput, TPath>

Explanation

forward allows you to forward the issues of the passed validation action via path to a nested field of a schema.

Returns

  • Action BaseValidation<TInput, TInput, TIssue>

Examples

The following examples show how forward can be used.

Register schema

Schema that ensures that the two passwords match.

const RegisterSchema = v.pipe(
  v.object({
    email: v.pipe(
      v.string(),
      v.nonEmpty('Please enter your email.'),
      v.email('The email address is badly formatted.')
    ),
    password1: v.pipe(
      v.string(),
      v.nonEmpty('Please enter your password.'),
      v.minLength(8, 'Your password must have 8 characters or more.')
    ),
    password2: v.string(),
  }),
  v.forward(
    v.partialCheck(
      [['password1'], ['password2']],
      (input) => input.password1 === input.password2,
      'The two passwords do not match.'
    ),
    ['password2']
  )
);

Related

The following APIs can be combined with forward.

Schemas

any, array, custom, looseObject, looseTuple, object, objectWithRest, record, strictObject, strictTuple, tuple, tupleWithRest, union, unknown, variant

Methods

omit, partial, pick, pipe, required

Actions

check, checkItems, empty, everyItem, excludes, filterItems, findItem, guard, includes, length, mapItems, maxLength, metadata, minLength, nonEmpty, notLength, partialCheck, rawCheck, reduceItems, someItem, sortItems

Utils

isOfKind, isOfType

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/forward/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API