final-form / final-form/react-final-form

Key-Value pair removed instead of updated when cleaning input field

Open
#614 2 comments 6 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

**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.

**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 to `empty string` or `null`, rather it just completely removes the key-value pair.

**Platform (please complete the following information):**
- React: 16.8.6
- React Final Form: 6.3.0
- Browser: Chrome
- Version: 76

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.