I have an email field that only gets shown if a checkbox is selected (boolean value is true
). When the form get submitted, I only what this field to be required
Formik author here...
To make Yup.when
work properly, you would have to add showEmail
to initialValues
and to your Yup schema shape.
In general, when using validationSchema
, it is best practices to ensure that all of you form's fields have initial values so that Yup can see them immediately.
The result would look like: