valibot.forward
第2引数はエラーが出た際に紐づけるpropertyを指定する
code:ts
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.'
),
)
);
code:ts
const CalculationSchema = v.pipe(
v.object({
a: v.number(),
b: v.number(),
sum: v.number(),
}),
v.forward(
v.check(({ a, b, sum }) => a + b === sum, '計算が正しくありません。'),
)
);