final-form / final-form/react-final-form

Updating fields in componentDidMount

Open
#409 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

### Are you submitting a **bug report** or a **feature request**?
Bug report

### What is the current behavior?
I have a case where I have two forms that operates on the same data but they also includes some other fields. The app uses redux so I save/restore form values from redux when switching between the tabs. I use one FormSpy with a component that batch update fields in componentDidMount/componentDidUpdate and one with a component that saves values on componentWillUnmount.

I change some fields and switch to the next tab. The values are restored in componentDidUpdate phase and all works fines ( pristine === false ), but after that I switch again to the previous tab where values are restored in componentDidMount phase and it looks like other part of the form is not notified ( pristine: true ) and in my case the Save component has form values equal to initial values.

### What is the expected behavior?
Form changes in componentDidMount to notify other parts of the form.

### Sandbox Link
https://codesandbox.io/s/m3195qyxk9

Steps to reproduce:
1) Type in last name some text
2) Switch to tab "Form 2" - the entered text in step 1 is available in second form and also the field is dirty which enabled the button to submit the form
3) Return back to tab "Form 1" - the entered text is available but form metadata is not updated - submit button is disabled.

### What's your environment?
"final-form": "4.11.0",
"react-final-form": "4.0.2",

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.