简体   繁体   English

React 故事书显示带有错误的 formik 表单

[英]React storybook showing formik form with errors

What is the simplest way to force a formik form to show fields in error?强制 formik 表单显示错误字段的最简单方法是什么?

I would like to this for a react storybook to show what our form looks like when a field has an error in it.我想要一个反应故事书,以显示当一个字段中有错误时我们的表单是什么样子。

Each field in my form will only display an error if it has been touched and its value is not valid.我表单中的每个字段只有在被触摸且其值无效时才会显示错误。

I can set the initial value of the fields but I can't figure out how to mark then all as touched so that the errors are displayed.我可以设置字段的初始值,但我无法弄清楚如何将所有内容标记为已触摸以便显示错误。

The Formik test for ErrorMessage might be of some use. ErrorMessageFormik 测试可能会有用。

Note the use of setFieldError and setError注意 setFieldError 和setError的使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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