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

Change to initialValues causes user input to be lost #832

Closed
kpdecker opened this issue Apr 20, 2016 · 14 comments
Closed

Change to initialValues causes user input to be lost #832

kpdecker opened this issue Apr 20, 2016 · 14 comments

Comments

@kpdecker
Copy link

If the initialValues object changes, non-conflicting user changes will be lost as the entire form is reset. While the correct behavior for the conflicting field case is a bit ambiguous, it seems like we should not invalidate user input in the event this changed.

export default reduxForm(GroupSettings.formProps,
/* istanbul ignore next */
(state) => {
  return {
    initialValues: state.group
  };
})(GroupSettings);
@kpdecker
Copy link
Author

npm ls | grep redux-form
├─┬ redux-form@4.2.2

@erikras
Copy link
Member

erikras commented Apr 20, 2016

We had a pretty long discussion about this on #370.

@Poplar-hills
Copy link

Poplar-hills commented Apr 21, 2016

I'm having the same issue with v5.1.1 -- if the initialValues object changes, all the input fields will be overwritten by a redux-form/INITIALIZE action.

Will this issue be addressed in v6.0.0?

@erikras
Copy link
Member

erikras commented Apr 22, 2016

If the past is anything to go by, there will soon be complaining that they were depending on the value overwriting. 😃 I do, however, agree with you guys that it should not overwrite the current form values when initialValues changes (if the form as already been initialized). People that want to do that can dispatch INITIALIZE manually.

Fix published as v5.1.2 v5.1.3.

@kpdecker
Copy link
Author

Thank you!

@Poplar-hills
Copy link

Thanks a lot!

@kromit
Copy link
Contributor

kromit commented Apr 25, 2016

Using 5.1.3 and value is now always ''. Only initialValue has the value. All my forms are broken now. I did not expect this from bugfix version change... :(

My form is displayed along with the list and it is expected that all user values are overwritten when new item is selected from the list. There should be a better communication about such breaking changes. At least the old behavior should be the default not the new.

5.1.1 is working as expected

@erikras
Copy link
Member

erikras commented Apr 26, 2016

@kromit I apologize for that. 😞

People clearly have different expectations about this.

@erikras
Copy link
Member

erikras commented Apr 26, 2016

Okay, guys. @kromit convinced me that initializing every time initialValues changes is the way to go. For those of you that don't want that, you will need to specify overwriteOnInitialValuesChange: false to negate this behavior. This has been published as v5.2.1. Apologies for the vacillation.

@EddyBorja
Copy link

EddyBorja commented Apr 30, 2016

Is there a way to allow an overwrite only for fields that have a different initial value from the previous initialValues?

Currently, if a user is editing a large form and just one initialValue is changed, it seems the entire form re-renders and the user loses whatever new inputs they entered, all for that one value.

@kpdecker
Copy link
Author

@EddyBorja I believe this is the behavior with the overwriteOnInitialValuesChange flag set to false.

@EddyBorja
Copy link

@kpdecker I tried it, and it seems like the initialValues are never changed from what they were the first time they are set.

In my scenario, my initialValues actually start off as blank strings, because my container needs to fetch data from the DB to populate the initialValues. Once the data comes in, it sets the initial values for the form based off the data it gets back.

However, by setting overwriteOnInitialValuesChange to false, the initial values never change from their blank strings, nor when any other updates are made to the data in the DB.

This is within a Meteor app.

@erikras
Copy link
Member

erikras commented Jul 1, 2016

Published enableReinitialize flag in v6.0.0-rc.1.

@lock
Copy link

lock bot commented Jun 2, 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 2, 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

5 participants