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

reset to "latest" initialValues #561

Closed
rhythnic opened this issue Jan 18, 2016 · 8 comments
Closed

reset to "latest" initialValues #561

rhythnic opened this issue Jan 18, 2016 · 8 comments

Comments

@rhythnic
Copy link

After updating initialValues and then resetting the form, the the form resets back to the original initialValues and not the latest initialValues. Is this the intended behavior?

When a new user is selected, I'm using the form plugin to return undefined

UserForm: (state, action) => {
    switch(action.type) {
      case 'LOAD_TARGET_USER':
        return undefined;
      default:
        return state;
    }
  }

and loading initial values through mapStateToProps.

export default reduxForm({form: 'UserForm', fields},
(state) => { return {initialValues: state.user.target} })
(UserForm);

Both resetForm() and destroyForm()+initializeForm(targetUser) reset the user info to the first user that was selected, instead of the most recent. Is there a better way to do this?

@rhythnic
Copy link
Author

Fixed this issue by setting targetUser to null when a userId is selected then load selected user object in a following action.

@Aaronius
Copy link
Contributor

This seems to be my problem as well. I'm not using a form plugin.

@Aaronius
Copy link
Contributor

Nevermind, my problem was that when I was resetting the form I was calling:

store.dispatch(reset());

Rather than passing the form name:

store.dispatch(reset('formName'));

@erikras
Copy link
Member

erikras commented Jan 21, 2016

Is this the intended behavior?

Yes. #370 (comment)

@erikras erikras closed this as completed Jan 21, 2016
@elisechant
Copy link

The "workaround" if anyone is wondering, is to use enableReinitialize=true on props.

@alllx
Copy link

alllx commented Apr 11, 2018

To reset form from outside of ReduxForm component:

import { reset } from 'redux-form';
mapDispatchToProps(dispatch) {
  return {
    resetForm: dispatch(reset('FORM_NAME')),
  }
}

To reset form inside ReduxForm component:
this.props.reset();

@eaconde
Copy link

eaconde commented May 1, 2018

I'm not sure why but setting the enableReinitialize=true doesn't work on my case. However, manually triggering the reset on the form does.

@lock
Copy link

lock bot commented May 1, 2019

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 May 1, 2019
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