Skip to content
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

How to reset the form after async call #11

Closed
cjroebuck opened this issue Aug 5, 2015 · 7 comments
Closed

How to reset the form after async call #11

cjroebuck opened this issue Aug 5, 2015 · 7 comments

Comments

@cjroebuck
Copy link

Say I have a login form that submits credentials to my api server. I don't want to call this.reset() in the components submit handler because I'm not sure yet whether the user logged in successfully.

So my form component listens on something like auth.isLoggedIn from global state and in componentWillReceiveProps I check the value of this prop. If nextProps.isLoggedIn is true, I redirect and now I want to reset the form. The trouble is, resetting the form within componentWillReceiveProps leads to an infinite loop. So the question I have is where is the best place to call reset without getting into this issue?!

Thanks!

@Gazler
Copy link

Gazler commented Aug 6, 2015

I did something like:

    dispatch({
      type: types.CREATE_POST_SUCCESS,
      post: res.body
    });
    dispatch({
      type: "REDUX_FORM_RESET"
      form: "newPostForm"
    });

I'm not sure if the constants are exported anywhere to prevent using the string directly.

@erikras
Copy link
Member

erikras commented Aug 10, 2015

The actions are exported now.

import {reset} from 'redux-form';
...
dispatch(reset('myForm'));

@erikras erikras closed this as completed Aug 10, 2015
@tnguyen14
Copy link

In the reducer, how would the resetForm method be called?

@tnguyen14
Copy link

Oh, I just realized that just dispatching the reset action is sufficient, I don't have to call resetForm manually.

@erikahazle
Copy link

I'm dispatching reset('myForm'), which successfully resets all of the text input fields but not the files input field. Do I need to do something in particular to reset that?

@abdalla
Copy link

abdalla commented Mar 3, 2016

the textarea component is not being clean using dispatch(reset('myform')) :(

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants