最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React yup validation leads to promise error field.resolve is not a function - Stack Overflow

programmeradmin4浏览0评论

I've followed tutorials on yup and tried many ways to do this but don't understand the error on simple form validation. I get the error field.resolve is not a function.

This is the snippet of code inside the onClick function:

const registrationSchema = yup.object().shape({
      username: yup.string().required,
      email: yup.string().email().required,
      password: yup.string().min(0).max(10).required,
    });

    const formData = {
      username: registerUsername,
      email: registerEmail,
      password: registerPassword,
    };

    const answer = registrationSchema.isValid(formData).then(function (valid) {
      console.log("works");
    });

I'm really confused over how and why this is't working.

I've followed tutorials on yup and tried many ways to do this but don't understand the error on simple form validation. I get the error field.resolve is not a function.

This is the snippet of code inside the onClick function:

const registrationSchema = yup.object().shape({
      username: yup.string().required,
      email: yup.string().email().required,
      password: yup.string().min(0).max(10).required,
    });

    const formData = {
      username: registerUsername,
      email: registerEmail,
      password: registerPassword,
    };

    const answer = registrationSchema.isValid(formData).then(function (valid) {
      console.log("works");
    });

I'm really confused over how and why this is't working.

Share Improve this question asked Oct 30, 2022 at 13:19 Joseph WalshJoseph Walsh 761 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Your required should be required() like:

const registrationSchema = yup.object().shape({
  username: yup.string().required(),                // <--
  email: yup.string().email().required(),           // <--
  password: yup.string().min(0).max(10).required(), // <--
});

const formData = {
  username: registerUsername,
  email: registerEmail,
  password: registerPassword,
};

const answer = registrationSchema.isValid(formData).then(function (valid) {
  console.log("works");
});

Credit: https://github./jaredpalmer/formik/issues/1040#issuement-624803999

发布评论

评论列表(0)

  1. 暂无评论