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

How to get only changed fields? #396

Open
juicylevel opened this issue Dec 12, 2018 · 4 comments
Open

How to get only changed fields? #396

juicylevel opened this issue Dec 12, 2018 · 4 comments

Comments

@juicylevel
Copy link

juicylevel commented Dec 12, 2018

feature request

Hello! I use FormSpy to handle form field changes. I need to know which fields have changed. How can i do this?

P.S. dirtyFields do not fit

@iskandarovBakshi
Copy link

you can use deep-object-diff package to know which fields changed, diff(initialValues, values)

@elissaioskon
Copy link

elissaioskon commented Apr 21, 2020

I was also searching about how i could implement this.

I post the solution that i used for any next visitor:
Second param that is passed at onSubmit function https://final-form.org/docs/react-final-form/types/FormProps#onsubmit is named form.

You can use form.getState().initialValues and compare them with the first param of onSubmit which is values.
The comparison could happen using an external library like deep-object-diff or a custom diff function.

@steventilator
Copy link

@juicylevel I don't know what you mean with "dirtyFields do not fit", but for everyone else: form.getState().dirtyFields gives you the fields that have changed.

@Basovs
Copy link

Basovs commented Feb 13, 2023

@juicylevel I don't know what you mean with "dirtyFields do not fit", but for everyone else: form.getState().dirtyFields gives you the fields that have changed.

"dirtyFields" doesnt work in multistep forms where each step mount and unmounts, "dirtyFields" resets/forgets step 1 dirtyFields when for example going from step 1 to step 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants