Describe the bug
I just came across something probably considered a feature that may cause some headaches and I'm not sure it's intended behaviour and if so, would love to know why.
If a field, (let's say a non-required text input, such as middle-name of a user), is pre-populated through initialValues, and such text is then manually removed by the user. Instead of setting such key's value to empty-string or null, it would instead completely remove the key-value pair of the internal state.
This means that if you were to send that state object to your API, the change made by the user (in this case, removing their own middle-name), wouldn't be a part of the set of changes sent, and so, it wouldn't be modified.
There obviously are many ways around this. For starters, you could just check for that condition and populate that state object on submission yourself. I'm just wondering if this behavior is intended and if so, why.
Just manually remove the middle name's text on the bottom of the form and look at how the values in state change just below.
Expected behavior
The state values don't reflect the middleName value to change to empty string or null, rather it just completely removes the key-value pair.
Platform (please complete the following information):
Describe the bug I just came across something probably considered a feature that may cause some headaches and I'm not sure it's intended behaviour and if so, would love to know why.
If a field, (let's say a non-required text input, such as middle-name of a user), is pre-populated through
initialValues
, and such text is then manually removed by the user. Instead of setting such key's value toempty-string
ornull
, it would instead completely remove the key-value pair of the internal state.This means that if you were to send that state object to your API, the change made by the user (in this case, removing their own middle-name), wouldn't be a part of the set of changes sent, and so, it wouldn't be modified.
There obviously are many ways around this. For starters, you could just check for that condition and populate that state object on submission yourself. I'm just wondering if this behavior is intended and if so, why.
To Reproduce https://codesandbox.io/embed/react-final-form-simple-example-9rzur React Final Form Simple example with
initialValues
pre-populated.Just manually remove the middle name's text on the bottom of the form and look at how the values in state change just below.
Expected behavior The state values don't reflect the
middleName
value to change toempty string
ornull
, rather it just completely removes the key-value pair.Platform (please complete the following information):