I want the favoriteAlcohol field to be validated/required only if props.isAdult passed to the component is true.
Yup.object().shape({
favoriteAlcohol: Yup.string().when(props.isAdult, {
is: true,
then: Yup.string().required(),
}),
name: Yup.string().required('Nazwa jest wymagana'),
})
How can I do that?
Above solution does not work, because when takes form's "keys" as a first argument, and I passed prop.
One working solution would be to map prop.isAdult to isAdult form value field, and then I could pass 'isAdult' as a first argument to the when() function. Not the best solution, though.