CodingYourLife
CodingYourLife

Reputation: 8616

How to show Form error summary using Formik with yup validationSchema

I want to show a summary of all errors found by yup validationSchema.

My CodeSandbox example: https://codesandbox.io/s/7m3n44po80

This is how it should look like

How it should look like if there are errors on submit. In the screenshot the error summary is hardcoded just as in my CodeSandbox: Error Summary

I couldn't find any "hook" where I can grab all the validation errors.

Upvotes: 5

Views: 9096

Answers (2)

Vencovsky
Vencovsky

Reputation: 31693

You can get the errors from props

errors is an object with the name of each field with an error.

Here is an example

Upvotes: 2

CD..
CD..

Reputation: 74176

You've got an errors prop passed to your component when using withFormik

For example: https://codesandbox.io/s/j216zmo0xw

Upvotes: 8

Related Questions