redux-form: Uncaught Error: You must either pass handleSubmit() an onSubmit function or pass onSubmit as a prop
I’m using this example here, and I get this error:
Uncaught Error: You must either pass handleSubmit() an onSubmit function or pass onSubmit as a prop
I’m using this with redux-form 3, and I’m using a Modal to display the content, is a dumb component, so is not connected to redux. Is there anything I’m missing here?
Thanks!
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 24 (2 by maintainers)
Commits related to this issue
- In docs, GettingStarted section, clarify form values retrieved via onSubmit (#190) — committed to miketrexler/redux-form by miketrexler 8 years ago
- Documentation updates (#1883) * In examples, update broken relative links * In docs, GettingStarted section, clarify form values retrieved via onSubmit (#190) * Fix omission in gettingstarted e... — committed to redux-form/redux-form by miketrexler 8 years ago
- [Bug Fix] Prevent form from submission when user press enter Form will be refreshed if users press enter. This is not desirable because the search should be performed while users are typing. Refer to... — committed to GovWizely/zAPIness-search-widget by yih-en 7 years ago
The documentation…or lack there of, on this is super annoying. Just to be clear for others with this problem I did below which works
Don’t be fooled and do the intuitive thing which would be to define a prop of
handleSubmit
on your instantiated JSX<ContactForm handleSubmit={myFunc}>
😢@sidazhou, the way I fixed it, is to pass a function to the handleSubmit function provided by redux-form:
<form onSubmit={handleSubmit(this.myOwnFunction)}>
. handleSubmit has to be provided trough the props:const { handleSubmit } = this.props
.This is why the FAQs mention the difference between
onX
andhandleX
.I’ll write it here again because is how I finally understood it and maybe is easier for other beginners as myself.
This is what worked for me:
The parent
I’ve understood what was the problem:
onSubmit
has to be defined on the parent of the formYou would expect the child
has
this.props.onSubmit
to be available to you. However, redux-form changes it tothis.props.handleSubmit
instead. To reiterate, in the Child,this.props.handleSubmit == myFunc
@EnriqueSalazar Thank you so much for calling your submit function
mySubmit
instead ofhandleSubmit
oronSubmit
. This is perhaps one of the main reasons why most other examples I’ve read were very confusing until I read yours.In general, I feel like all the examples I’ve read contain too many occurrences of the word
submit
. It becomes too easy to mix upsubmit
,handleSubmit
,onSubmit
,"submit"
, etc. After seeingsubmit
about 5 times (with slightly different prefixes and suffixes), it becomes too easy to miss some variables/functions and end up confused.It also doesn’t help that many examples seem to be explaining two different ways of doing this, while not clearly showing the two options side by side.
Hmm i am getting this error in a
Remote Submit
occasion inv7.4.2
. I call it like this:and my form is this:
@fakiolinho, @adamfaryna, @jasperkuperus and anyone else having a similar issue trying to pass an
onSubmit
handler tohandleSubmit
like:I believe the solution is to use the
Form
component which was added in version 6.4.0 (at least according to the docs). Switching out<form>
for<Form>
immediately resolved my issue, and the documentation seems to support that this is the component’s intended use case:This is how I bound my form handler (handleFormSubmit) to the handleSubmit:
If you are using containers in this case, do check if you are returning Onsubmit function from mapDispatchtoProps.
I stumble upon the same issue. It looks like bug.
@EnriqueSalaza code started working after gone through your example