使用Formik+Yup实现表单提交以及验证

Cris

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

阅读 1.1k
36 声望
0 粉丝
0 条评论
36 声望
0 粉丝
文章目录
宣传栏