forward
Forwards the issues of the passed validation action.
const Action = v.forward<TInput, TIssue, TPath>(action, path);
Generics
TInputextends Record<string, unknown> | ArrayLike<unknown>TIssueextends BaseIssue<unknown>TPathextends RequiredPath
Parameters
actionBaseValidation<TInput, TInput, TIssue>pathValidPath<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
ActionBaseValidation<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
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/forward/