You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Are you submitting a bug report or a feature request?
bug report
What is the current behavior?
Currently, when adding an item into an array key, and then removing the last one, the key gets removed from the original object, no matter if the key was initialized as an empty array.
What is the expected behavior?
Keep the key in the form values, as an empty array.
I was facing the same issue with recent update of 3.1.0. With this update, the behaviour of remove and removeBatch has been changed. Checkout the release notes for more info.
Temp Fix
Just revert final-form-arrays back to 3.0.2 and all good.
Long term solution
For a long terms solution, I think it is better to always consider form fields as optional. There might be other cases where the code might not work if we don't handle it. I am migrating my codebases to handle these cases. Also worth noting that a field's values (useField) is returned as empty string ('') when it's not defined, even for arrays. So this should be handled as well. In summary
Any field in the form can be undefined
Always check for field type (array/string/object) before doing any manipulation or operations
Having to deal with optionality adds unnecessary complexity to me. Previously (with 3.0.2), we could initialize the value to [] and only deal with arrays, now (3.1.0) we have to sprinkle ?./?? etc. all around. I guess now it would be better to initialize to undefined instead, to notice possible problems with it more easily.
Are you submitting a bug report or a feature request?
bug report
What is the current behavior?
Currently, when adding an item into an array key, and then removing the last one, the key gets removed from the original object, no matter if the key was initialized as an empty array.
What is the expected behavior?
Keep the key in the form values, as an empty array.
Sandbox Link
https://codesandbox.io/s/react-final-form-field-arrays-forked-xopb2v
What's your environment?
The text was updated successfully, but these errors were encountered: