Spec-Zone.ru › Valibot

forward

Перенаправляет ошибки переданного действия валидации.

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

Дженерики

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

Параметры

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

Описание

forward позволяет перенаправлять ошибки переданного валидационного action через path во вложенное поле схемы.

Возвращаемое значение

  • Action BaseValidation<TInput, TInput, TIssue>

Примеры

В следующих примерах показано, как можно использовать forward.

Схема регистрации

Схема, которая проверяет совпадение двух паролей.

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']
  )
);

Связанное

Следующие API можно комбинировать с forward.

Схемы

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

Методы

omit, partial, pick, pipe, required

Действия

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

Утилиты

isOfKind, isOfType

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

Spec-Zone.ru

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