You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a form that contains 3 text fields, one of them is totally optional and is hidden, where it can be displayed by clicking on the button (this appears).
The problem
In the previous scenario, how can I validate this type of form using Yup?
The idea
The main idea is that if you submit the form with two empty fields, it throws the Yup schema required errors, but if you activate the switch to show the third field, it is also required before submitting.
I tried to use Yup.lazy but without success in the integration with Formik.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Scenario
In a form that contains 3 text fields, one of them is totally optional and is hidden, where it can be displayed by clicking on the button (this appears).
The problem
In the previous scenario, how can I validate this type of form using Yup?
The idea
The main idea is that if you submit the form with two empty fields, it throws the Yup schema required errors, but if you activate the switch to show the third field, it is also required before submitting.
I tried to use Yup.lazy but without success in the integration with Formik.
Any help with this?
Beta Was this translation helpful? Give feedback.
All reactions