问题
I am using redux-form v6.0.1
.
Right now, my use-case involves creating a form where:
- Errors are only displayed
onSubmit
, whensubmitFailed
prop istrue
. - 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
.
来源:https://stackoverflow.com/questions/39235203/display-validation-errors-onsubmit-with-redux-form-and-clear-errors-until-next