-
-
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
v6 removes keys from form.<formname>.values
object
#879
Comments
Yeah, ever since React |
It seems like the correct thing to do is use |
|
Right, that's what I meant though - if redux form passes Also, if a user wants them to be removed, it's a lot easier to remove keys with a value of _.pickBy(formData, (val, key) => val !== "") vs. // need to pass around extra array of fields that are supposed to be on the object
expectedFields.forEach(field => {
if (!formData.hasOwnProperty(field)) formData[field] = '';
}); But as I mentioned above, a config option passed to |
The reason the value is getting deleted is to preserve the behavior that if you have a form with no initial values, and you type something into an input, and then you erase it, the form should be Writing a |
Support setting a field that has been initialized to "". Fixes #879
I think this was fixed by #924. Release coming sometime next week. |
Published as |
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. |
I'm not sure if this is the intended behavior, so please correct me if I'm wrong.
If you set the
initialValue
on an input field to a string value, and then delete (i.e., press backspace) the string in the input field, theform.<formname>.values.field
property for that input field is missing in the state tree. It seems to me it would make more sense to leave the empty string there, rather than deleting the property.For me, this came up when using the
<formname>.initial
and<formname>.values
objects to create a JSON patch. I expected the patch to look like this:{ op: "replace", path: "/field", value: "" }
but instead it looks like this:
{ op: "remove", path: "/field" }
which is incorrect. I am not removing the field from the form, I am simply setting it equal to a null string. That's when I noticed that the key was actually missing from the state tree.
However, I can see that this would be useful in the case where you actually wanted a null-string to eventually resolve to
undefined
somewhere down the line. Perhaps this should be a prop we can set on the form -emptyStringToNull
or something?The text was updated successfully, but these errors were encountered: