0
votes

Hello I am trying to achieve error validation with Yup and Formik and I cannot figure out how to get it working with just an array of strings. There no examples of simple arrays of Formik and Yup.

I am simply trying to use the required() method to ensure the user enters at least one friend before they are allowed to press submit. For some reason I am not getting anything in my errors though.

I created a codesandbox for anyone that would like to help me. https://codesandbox.io/s/stupefied-fire-ksbid?file=/src/App.tsx

Thanks in advance!

1

1 Answers

1
votes

You called your field description in the schema when it should be friends. You can also add .min(1) to make sure there's one. I always add .trim() too so empty strings aren't accepted, unless people can have friends called " ".

const validationSchema = yup.object().shape({
  friends: yup.array().min(1).of(yup.string().trim().required())
});