title: Conditional Validation in Yup
body: <p>I have an email field that only gets shown if a checkbox is selected (boolean value is <code>true</code>). When the form get submitted, I only what this field to be required if the checkbox is checked (boolean is true).  </p>
  
  <p>This is what I've tried so far:</p>
  
  <pre><code>    const validationSchema = yup.object().shape({
         email: yup
               .string()
               .email()
               .label('Email')
               .when('showEmail', {
                   is: true,
                   then: yup.string().required('Must enter email address'),
               }),
          })
  </code></pre>
  
  <p>I've tried several other variations, but I get errors from Formik and Yup:</p>
  
  <p><code>Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
      at yupToFormErrors (formik.es6.js:6198)
      at formik.es6.js:5933
      at &lt;anonymous&gt;
  yupToFormErrors @ formik.es6.js:6198
  </code></p>
  
  <p>And I get validation errors from Yup as well. What am I doing wrong? </p>