-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Impossible to clear last field in a form when initialValues is an empty object and the form was submitted #2597
Comments
We've also been running into this. Just to give a little more background, this is the line in the CHANGE reducer that causes it: let result = state
const initial = getIn(result, `initial.${field}`)
if (initial === undefined && payload === '') {
result = deleteInWithCleanUp(result, `values.${field}`)
} else if (payload !== undefined) {
result = setIn(result, `values.${field}`, payload)
} The behavior here is that if let values = getIn(formState, 'values') || initial This bug appears when Example use case:A concrete use case is storing last submitted form values in the URL:
A potential workaroundInstead of setting --- const r = (state = { initialValues: {} }, action) => {
+++ const r = (state = { initialValues: undefined }, action) => { The only problem with this is that it will submit with an empty string for the cleared value, which might or might not work for you. |
Fix released in |
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. |
A bug report
What is the current behavior?
Given that the form is being passed an empty object to
initialValues
prop, and then the form has been submitted, after clearing last field of this form (for e.g. with a backspace button) it will still return last field's value inonSubmit
handler.An example is here:
https://jsfiddle.net/piteer/o4wjnjyz/2/
You need to fill one field and then press submit, then clear the field and again press submit. This will return last submitted value.
Also worth mentioning: If you fill any other field and submit a form again, last previous field will again be empty as it should be.
What is the expected behavior?
Value send to a
onSubmit
handle should represent form state, not the last submitted state.Other informations
It can be workaround by checking if initialValues object is empty and passing null instead. Then the form will work as expected.
The text was updated successfully, but these errors were encountered: