New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Form is refreshing after submit #1270
Comments
same here |
@NeXTs I get the same thing. |
Then you could temporarily use |
That is very bizarre. I'm not seeing that at all. For example, the submit validation example doesn't exhibit this behavior. You don't see this if you go back to 6a15? |
Sure, I've tried many various releases, neither 6a15 or 6a6 helps I managed my dependencies to be exactly like in your example, but without luck I have a hunch that this is due to the react-router or redux-auth-wrapper, checking right now |
@erikras Well, I'm tired Please take a look at this example in your free time, I have no more ideas what could be wrong as for this moment.
there would be single input field and submit button by clicking which I got response that I attached as image. component path |
Hm, looks like redux-form differs between that one in examples and published into npm or something @erikras In theory if I set up redux-form@v6.0.0-rc1 material ui example on my local machine, then go to /examples/material-ui and do this should works seamlessly, as soon as plugin's sources expected to be same, right? and console.log of field argument in renderTextField shows this |
@NeXTs The source code that is identical to the npm published lib is going to be under the specific tag for that version. https://github.com/erikras/redux-form/tree/v6.0.0-rc.1/ That goes for the examples as well. I have already made changes to the examples in the |
ok nevermind, things became much better after updating react-hot-reload@3.0.0 from alpha to beta version. |
I'm having the same page reload problem after submitting with |
I suppose you have also incorrectly use onSubmit function. so that your submit function wrapped in redux-form's submit function which prevents form submittion and does all other necessary job |
Thanks a lot 👍 I clearly missed that part in the documentation |
You're welcome! |
I had the same issue with my page refreshing on form submit. |
I still can't resolve the issue. I don't understand solution too well since I'm new to React. Can someone provide their code or a deeper explaination? Thanks! |
@aspdev91, https://github.com/lakesare/memcode/search?utf8=%E2%9C%93&q=onSubmit |
Thank you, but I still can't quite resolve it.. It says onSubmit is undefined. I am not exporting the code to any other modules or using hot reloading etc. Thanks!
|
not somewhere but in parent's component where you define this Form, like
p.s. and yes, while defining Form you specify |
I get the same problems (refreshing, if I don't manually call For submitting I do
Thank you in advance for any help/advice |
@AndreasHoermandinger pay attention to #1270 (comment) |
@NeXTs I got
Is this the problem? (in the examples only functions are used, I am using a class) |
@NeXTs I am still seeing this issue on latest redux form in ie11. parent component has
and form component has
|
@kellyrmilligan at ie11 only? |
yep, as far as I can tell. I haven't had a good chance to look, but where is it calling prevent default on the submit event? |
I see where it is doing this now. will check to see if the event is different in IE11 for some reason. |
it looks like nothing is actually working in ie11, this is on browserstack anyway. no validations are running, etc. |
I was struggling with this issue as well but really reading #1270 (comment) helped me out. It appears reduxForm takes your passed Gotchas:
Quick breakdown of the goods and bads for clarity:
Breakdown of inside SampleForm class:
Hopefully that breakdown saves some headscratching for people coming here from google searches. |
Has anyone been able to see if ie11 is working? My form works everywhere but there |
I could not get this to work. Ended up using |
I believe the main reason for the confusion here is that redux-form actually injects Instead, you only need to pass in an const MyForm = (props) => {
const { handleSubmit, onSubmit } = props; // Notice two functions, not one! Only onSubmit is passed in by you as a prop. The other is passed in by redux-form
return (
<form onSubmit={handleSubmit(onSubmit) }>
<Field component="input" type="text" name="body" />
<button type="submit">Submit</button>
</form>
)
} Then you would use it like this (note how I am not passing in handleSubmit): <MyForm onSubmit={someFunctionThatWillHandleFormValues}/> Here is a reference to an article that made me realize that. Check out the code sample. |
just got back to testing this out again. can't pin down what change made the fix, but in between 6.1.1 and 6.2, ie11 was throwing an error in 6.1.1 I can now actually use this library :) in the compiled reduxForm.js, it's line 13. this seems like a change in babel pherhaps? or corejs? |
#1270 (comment) solved it for me. I moved the submit function out of the form class into the parent class and supplied it as |
Please, don't pass Better yet, replace it with something like
|
This had me stumped for a while. I finally resolved it by passing the default handleSubmit prop my own handleSubmitForm function =========================================================
|
This is an extremely confusing problem, and required quite a few re-reads through the comments above. This should definitely be rethought, refactored, or at least have updated documentation that clarifies this problem. If anyone gets to the end here and still doesn't understand I'll try another explanation. If you were like me, then your first thought from reading the docs might be to try:
This will cause the refresh problem. That is because you are not supposed to put your function inside In order to run a function with the form results, it needs to sit outside the component where you declare
Where inside The confusing bit is that both the inner and outer function must both use |
I had the same issue, wasted some hours trying to figure out, I think it should have more visible since you have to do EXACTLY like @NeXTs said |
I also needed to declare onSubmit function in my form class and found the solution of @mcverter working fine. As this is what most people here are looking for I believe this should be the recommended solution. |
why the hell #1270 (comment) is not in docs? |
I agree with @Stas-Buzunko. It should be made clear in the docs that the handler needs to be passed in from outside the form component. I had assumed that this functioned the way most other components do and I could just pass |
+1 for making this clear in the docs and examples, I also spent an hour or so on it :-) |
PRs are welcome. |
+1 for marking this clear in the docs. I expected this to work exactly like all other components. I lost the whole day solving this problem. Oh... ps: If I were a little stupider, and just copied an example from the documentation, this would not happen. Or vice versa? |
Had the similar issue with onSubmit and handleSubmit. component:
container
action creator
Hope that the example I've provided can help someone to save some time. |
@gustavohenke if I were to submit a PR, would you say that FAQs are the most appropriate section for this common problem? EDIT: never mind - looking at the faqs, I see now that there's already a relevant entry. |
Elaborated on the `onSubmit` vs. `handleSubmit` FAQ in an attempt to address some of the confusion witnessed in redux-form#1270.
Elaborated on the `onSubmit` vs. `handleSubmit` FAQ in an attempt to address some of the confusion witnessed in #1270.
Form will be refreshed if users press enter. This is not desirable because the search should be performed while users are typing. Refer to redux-form/redux-form#1270, handleSubmit supposes to do e.preventDefault() to preview form from submitting. Also, refer to redux-form/redux-form#190, we need to pass onSubmit as props to the form
use e.preventDefault() |
I haved faced the same problem and that's my fault to inject wrong name in Redux form. |
I solved this issue by throwing a 'Submission Error' in my action creator. Because my API would send a status '200' when there was an issue with the user's login input, the form would submit and then refresh with the user's input gone because my authentication would kick it back. The example and documentation for Submission Error from the Redux-Form api is here. I went ahead an put it in my action creator in the second ' .then ' statement I set up.
This I bound my form handler to the handleSubmit:
I had no issues with my data not being accessible in my action creator/in the component. |
It should be placed on the first page of documentation with bold and other attention marks !!! IMPORTANT !!! Because already 4+ years this issue happen with many people |
Guys, another one here spending hours in this. |
<form onSubmit={props.handleSubmit(formData => {
// this is your submit function
})}>
{/* form contents */}
</form> |
@iamandrewluca Thanks! |
@dsldiesel This is not a workaround 🙂 |
Hi, I have a simple stateless form component and after I click Login button my page is refreshed.
How can I prevent my page from refreshing?
I use redux form 6 rc1
The text was updated successfully, but these errors were encountered: