forward
Перенаправляет ошибки переданного действия валидации.
const Action = v.forward<TInput, TIssue, TPath>(action, path);
Дженерики
TInputextends Record<string, unknown> | ArrayLike<unknown>TIssueextends BaseIssue<unknown>TPathextends RequiredPath
Параметры
actionBaseValidation<TInput, TInput, TIssue>pathValidPath<TInput, TPath>
Описание
forward позволяет перенаправлять ошибки переданного валидационного action через path во вложенное поле схемы.
Возвращаемое значение
ActionBaseValidation<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
Утилиты
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/forward/