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

Reinitialize non-registered values with keepDirtyOnReinitialize #311

Merged
merged 3 commits into from
Jan 22, 2020

Conversation

Dragomir-Ivanov
Copy link
Contributor

When keepDirtyOnReinitialize is not set, all non-registered values go to form.values, which is useful for computed values depending on such non-registered values. Replicate the same behavior when keepDirtyOnReinitialize is set as well.

@codecov
Copy link

codecov bot commented Dec 21, 2019

Codecov Report

Merging #311 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #311   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          12     12           
  Lines         560    560           
  Branches      116    116           
=====================================
  Hits          560    560
Impacted Files Coverage Δ
src/FinalForm.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2047e0...2fd7dee. Read the comment docs.

…eepDirtyOnReinitialize is not set, all non-registered values go to `form.values`, which is useful for computed values depending on such non-registered values. Replicate the same behavior when keepDirtyOnReinitialize is set as well.
@erikras
Copy link
Member

erikras commented Jan 22, 2020

Can you explain this a little better, and maybe provide an example? I'm not following 100%.

@Dragomir-Ivanov
Copy link
Contributor Author

Dragomir-Ivanov commented Jan 22, 2020

Hi @erikras, of course. When updating initialValues and keepDirtyOnReinitialize={false}, all values get updated,

if (!keepDirtyOnReinitialize) {
   formState.values = values
}

but when keepDirtyOnReinitialize={true} only registered values(which are pristine) get updated. All other NOT registered(thus always pristine by definition) are not updated in the form internal values structure. I believe this is a bug, and given patch corrects the issue.

PS: I am short on time right now, so if you still need an example, I may provide one later this evening. Thanks!

src/FinalForm.js Outdated
if (pristine) {
// only update pristine values
formState.values = setIn(formState.values, key, getIn(values, key))
Object.keys(values).forEach(key => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only going to work with shallow/flat values objects. FF supports deep values like shipping.address.street, the metadata for which would be in safeFields['shipping.address.street'].

Let me think about it some more...

@erikras
Copy link
Member

erikras commented Jan 22, 2020

I think I fixed it.

@erikras erikras merged commit 0bf8dee into final-form:master Jan 22, 2020
@Dragomir-Ivanov
Copy link
Contributor Author

Thanks a lot! There is simple companion PR against react-final-form as well.
final-form/react-final-form#706

@erikras
Copy link
Member

erikras commented Jan 23, 2020

Published in v4.18.7.

@lock
Copy link

lock bot commented Feb 22, 2020

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 Feb 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants