validationSchema change depending on form values

<Formik
    initialValues={{ planType: 'PRE' }}
    validationSchema={() => yup.lazy((values) => {
      const isCPF = values.docType === 'cpf'

      return yup.object().shape({
        docType: yup.string(),
        number: isCPF ? yup.string().cpf() : yup.string().cnpj()
      })
    })}
    onSubmit={loadPlanActivation}
    render={this.renderForm}
  />

validationSchema change depending on form values #1228


Cris
42 声望1 粉丝