My react-hook-form with 3 step
return (
<section className="flex max-w-x">
<form onSubmit={handleSubmit(onSubmit)} className="mx-auto my-0 w-2/5">
<FirstStep
show={formStep === 1}
register={register}
errors={errors}
onNextClick={async () => {
setFormStep((await trigger(['email', 'password', 'passwordConfirm'])) ? 2 : 1);
}}
/>
<SecondStep
show={formStep === 2}
register={register}
errors={errors}
onNextClick={async () => {
setFormStep((await trigger(['firstname', 'lastname', 'middlename', 'typeClient', 'phone'])) ? 3 : 2);
}}
onBackClick={() => setFormStep(1)}
/>
<ThirdStep
show={formStep === 3}
register={register}
errors={errors}
onBackClick={() => setFormStep(2)}
isSubmitting={isSubmitting}
/>
</form>
</section>
);
and have yup validators for phone and email input
email: email.test(
'isUnique',
translate('signupFormScheme.email_is_busy'),
async (value) => !value || await AuthService.checkEmail(value) === true,
),
phone: phone.test(
'isUnique',
translate('signupFormScheme.phone_is_busy'),
async (value) => !value || await AuthService.checkPhone(value) === true,
).required(translate('signupFormScheme.phone_must_be_filled')),
When I push button on the first step, yup start work validation for email input, after then i push button on the second step and again start work validators for email input and phone. And then again I push buton Signup on the last step and again start work validation for email and phone input.
Why yup its do? because I use triger(react-hook-form) Thaks for answer