yupError.inner 在将架构与 Formik 集成时未定义

yupError.inner is undefined while integrating schema with Formik

我尝试将 Yup 的架构验证与 formik 集成。但是收到错误 yupError.inner 未定义 这是 link 到 codesandbox!

我没怎么试过。但是发现了这个错误报告。后来意识到要解决。但我仍然收到同样的东西。 Link 发布 #1486!.

// VALIDATION SCHEMA
const formSchema = Yup.object().shape({
    emailId: Yup.string("Enter a valid string")
      .email("Please enter a valid Email ID")
      .required("Need your Email ID, we won't spam you!"),
    confirmMail: Yup.string("Enter a valid string")
      .matches(Yup.ref("emailId"), "Email ID's are not matching")
      .required("Please enter a valid mailid"),
    mobileNo: Yup.number("Please enter number")
      .max(10, "You've entered more than 10 numbers")
      .min(10, "You've entered less than 10 numbers")
      .required("Password is required"),
    password: Yup.string("Enter a valid password").required(
      "Password field is required"
    ),
    confirmPassword: Yup.string("Enter a valid password").required(
      "Password fields are not matching"
    )
  });
          //Integration of Validation
          <Formik
            validate
            initialValues={this.initialValues}
            validationSchema={this.formSchema}
            onSubmit={this.handleSubmit}
          >
            {props => this.renderForm(props)}
          </Formik>

收到错误 yupError.inner 未定义

问题是匹配电子邮件字段的自定义验证。我创建了一个 fork here which I fixed using the method from this Github issue 来为 Yup 添加一个自定义验证方法来比较字段的相等性,这个功能显然没有得到很好的支持。

提高到 latest 并使用 mixed().test() 而不是 string().test()

示例:

passwordConfirm: Yup.mixed().test('is-same', 'Passwords not match.', value => value === values.newPassword)