1

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 Answer 1

4

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())
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.