final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.39k stars 481 forks source link

dirtySinceLastSubmit does not work within onSubmit #861

Open rogorman9 opened 4 years ago

rogorman9 commented 4 years ago

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.

bertho-zero commented 3 years ago

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

I use final-form@4.20.2 and react-final-form@6.5.3.

ericchernuka commented 2 years ago

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.

AndriyHromyak commented 2 years ago

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