redux-form: Calling submit action does not trigger validation
Are you submitting a bug report or a feature request?
This seems to be a bug.
What is the current behavior?
When submit
action is dispatched on form it just submits the data and totally ignores validation on either form or fields level.
What is the expected behavior?
When submit
action is dispatched then validaitons should be triggered.
What’s your environment?
redux-form@7.0.3
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 28
- Comments: 25 (4 by maintainers)
Disappointed to see no word still on this issue. I seem to be spending more and more time working around these quirks than just implementing without redux-form.
In addition to triggering on submit, it would be really useful to be able to dispatch an action which triggers async/sync validation manually.
The issue seems to be present in earlier versions aswell. The problem is present in the actual example on ‘Sync Validation’ in version 6.8: https://redux-form.com/6.8.0/examples/syncvalidation/ (Validate does not run when the form is untouched)
same issue here
@erikras Any plan to fix this?
There is no on-submit-validation, only on field change event. But fact you can create an invalid form, and next submit it, before touching anything. And it will be submitted.
It’s nice to know it’s an issue with the module… Thought I was going crazy!
I have this same issue. Is any temp solution for this?
fwiw, I was experiencing the same issues after resetting a form… but calling initialize instead of reset did the trick for me.
Quick update: re initializing does work, but it will not use your initialValues if you described any when you invoke the reduxForm HOC
@danielrob I can elaborate at least my specific case. We implement a Wizard leading the user through subsequent parts of a process.
Roughly the following happens:
redux-form
initialValues
if any are providedsubmit
action-creatorreset
action-creator upon successMy Solution: I assumed my understanding of what the
submit
action-creator does is not what I expected it to do. So first I tried toreset
the form. But as it says in the docs:I figured, this does not seem to touch the validation checks at all. So went code-digging. And it turned out to be even worse, because:
isValid
selector is cachedvalidExceptSubmit
prop which is set here.So I found this big hammer action-creator called
destroy
, which makes subsequent validation checks work for my case:)Hope that clarifies and may help others. IMHO I think in most cases the cause of this “bug” is just plain miss-understanding of how
redux-form
’s API is designed to work. Though may it’s possible that my initial expectation of how I think it will work would suit better for this use case 🤔Thanks @russellr86. I had the same issue where I was trying to reset my form and when the modal closed but then validation was broken the next time I re-opened it and tried to submit (reset seems to have removed the syncErrors array from the form node in redux??). Using initialize instead works.
Thanks @AndyOGo your scenario here is probably better captured by #2971.