react-final-form
react-final-form copied to clipboard
dirtySinceLastSubmit does not work within onSubmit
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.log
s 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.
I have the same issue, modifiedSinceLastSubmit
and dirtySinceLastSubmit
are always false in my FormSpy
.
I use [email protected] and [email protected].
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.
guys it's been 2 years, will there be fix for that?