react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

dirtySinceLastSubmit does not work within onSubmit

Open rogorman9 opened this issue 4 years ago • 3 comments

Are you submitting a bug report or a feature request?

Bug report

What is the current behavior?

dirtySinceLastSubmit is always false and dirtyFieldsSinceLastSubmit is always an empty Object when accessed via form.getState() within the onSubmit function.

What is the expected behavior?

dirtySinceLastSubmit should be true if the form values are different from the values it was last submitted with. false otherwise. Comparison is done with shallow-equals. dirtyFieldsSinceLastSubmit should be an object full of booleans, with a value of true for each field that has a different value from the one when the form was last submitted.

Sandbox Link

https://codesandbox.io/s/hidden-microservice-lmq65?file=/index.js This is forked from the submission errors example, with the only change being the addition of the console.logs and the second form argument to onSubmit.

To reproduce, submit the form once with any values. Then change either or both values and submit again. In the console, there will be false and an empty object logged regardless of which values were changed.

What's your environment?

React Final Form version 6.3.4 Final Form version 4.20.1

Other information

Similar to #692, but accessing dirtyFieldsSinceLastSubmit in a different way. modifiedSinceLastSubmit may have the same issue as well.

rogorman9 avatar Sep 24 '20 20:09 rogorman9

I have the same issue, modifiedSinceLastSubmit and dirtySinceLastSubmit are always false in my FormSpy.

I use [email protected] and [email protected].

bertho-zero avatar Jun 23 '21 16:06 bertho-zero

I actually just ran into this. I've confirmed this by also creating a decorator that handles a beforeSubmit/afterSubmitSucceeded/afterSubmitFailed and in the beforeSubmit calling form.getState(). dirtyFieldsSinceLastSubmit returns the changed values.

I haven't tried this, but a workaround might be to create a decorator that highjacks the original submit function and calls it with the diffed values if that's what you're looking for.

ericchernuka avatar Jan 14 '22 23:01 ericchernuka

guys it's been 2 years, will there be fix for that?

AndriyHromyak avatar Oct 26 '22 06:10 AndriyHromyak