简体   繁体   中英

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: 错误摘要

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

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

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

You can get the errors from props

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

Here is an example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM