Display validation errors onSubmit with redux-form

2019-07-15 00:07发布

问题:

I am using redux-form v6.0.1.

Right now, my use-case involves creating a form where:

  1. Errors are only displayed onSubmit, when submitFailed prop is true.
  2. When the user goes back to fix the errors, the errors go away, and don't redisplay until the next time onSubmit is called.

My current solution involves setting touchOnBlur: false, and having my error message display when touched && error. redux-form touches every field when onSubmit is triggered, so I add logic to every field to set touched = false when the user revisits, to hide the error until the next form submission. However, this seems very counter-intuitive (setting touched to false when the user touches things). Is there a more natural way to accomplish this?

回答1:

The default behavior is to clear the form-wide submit error when a field is changed. But this can be overridden by the persistentSubmitErrors config flag introduced in v6.0.4.



标签: redux-form