react-hook-form: Yup conditional fields, useFieldArray is not updating

Describe the bug I have a couple of issues.

  1. useFieldArray is not working well with yup. I have a yup schema like this:
  name: yup
    .array()
    .of(
      yup
        .string()
        .min(3, 'Company name is too short - should at be 3 chars minimum')
        .required(),
    )
    .max(3),

( Array of string that’s 3 charaacters minimum ) If you debug the error you can see that errors of this field does not update well. Most of the time it gets updated after submitting the form

  1. You need to type in several times to update the value of Chakra UI NumberInputField If you scroll down a little there’re two number inputs.

  2. I get an undefined error upon submitting the form without filling the conditional fields which are not rendered. here’s the schema code for the conditional fields

  hasBusinessAddress: yup.string().oneOf(["NO", "YES"]),
  address: yup.object().shape({
    line1: yup.string().when("hasBusinessAddress", {
      is: "YES",
      then: yup.string().required()
    }),
    line2: yup.string(),
    zipcode: yup.string().when("hasBusinessAddress", {
      is: "YES",
      then: yup.string().required()
    }),
    state: yup.string().when("hasBusinessAddress", {
      is: "YES",
      then: yup.string().required()
    }),
    country: yup.string().when("hasBusinessAddress", {
      is: "YES",
      then: yup.string().required()
    })
  })

Codesandbox link (Required) https://codesandbox.io/s/vigorous-mccarthy-ro7e2?file=/src/schema.tsx:950-1527

Desktop (please complete the following information):

  • OS: macOs Catalina 10.15.3
  • Browser: chrome
  • Version: 80.0.3987.149

Additional context Also, I noticed that in errors don’t get updated very well. e.g. you can check the errors with the yup schema

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (25 by maintainers)

Most upvoted comments

ah no. it’s fine. we can wait until the weekend. thank you

https://codesandbox.io/s/recursing-beaver-f64qt

thank you. when do you plan to release it ?

thank you very much

thanks a lot 👍

for the first issue https://codesandbox.io/s/vigorous-mendel-ksxtn?file=/src/App.tsx

the submit date looks valid, can you get the data and valid against your schema?

Screen Shot 2020-04-07 at 9 03 46 pm Screen Shot 2020-04-07 at 9 03 39 pm

image

name string must be 3 chars minimum. so in this case it still shows it as invalid