-
Notifications
You must be signed in to change notification settings - Fork 15
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`s values does not update when change initialValues #37
Comments
Hum, yeah, it's a bug, but that's not the correct fix. Say for example the form mounted with the following { name: 'Héliton', age: '26' } Then the user changed { name: 'Héliton', age: '27' } For some reason, you change { name: 'Harry', age: '28' } From my point of view, as name is not dirty, it should be changed to Harry, and age should remain 27, because it's dirty, the user changed it. In a nutshell, when you update What do you think? |
Yes, it makes sense. So what is the solution to this bug? |
Probably something like: componentWillReceiveProps(nextProps) {
if (isEqual(nextProps.initialValues, this.props.initialValues)) {
return
}
this.setState(prevState => {
const dirtyValues = (
Object.keys(prevState.values)
.filter((path) => this.isDirty(path))
.reduce((result, path) => ({
...result,
[path]: prevState.values[path],
}), {})
)
return {
values: {
...nextProps.initialValues,
...dirtyValues,
}
}
})
} Can you test please? |
Please test with deep paths too, e.g. |
Currently, on Form's componentWillReceiveProps, it does the following:
When I update initialValues prop, the values are not updated.
My solution was to change the merge order of the props, like this:
What do you think?
(I'm sorry for the English, it's not my native language.)
The text was updated successfully, but these errors were encountered: