乐趣区

关于前端:使用FormikYup实现表单提交以及验证

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

退出移动版