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

Autosave ignores fields that have been cleared

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

Description

### Are you submitting a **bug report** or a **feature request**?

Bug report

### What is the current behavior?

https://codesandbox.io/s/react-final-form-auto-save-on-field-blur-znm9f?file=/index.js

When autosaving a field that has a value in it (in the example either of the name fields show it) after clearing the value no autosave is fired.

### What is the expected behavior?

Clearing a value is still a change to the data and should be autosaved normally.

### Sandbox Link

https://codesandbox.io/s/react-final-form-auto-save-on-field-blur-znm9f?file=/index.js

This is a copy of the autosave on blur example with defaults put in for firstName and lastName to make it easier to demonstrate. You get the same result on the original by adding a value, triggering the autosave by blurring and then clearing the value.

### What's your environment?

Final Form 4.20
React Final Form 6.5.0

MacOS Version 10.15.3 (19D76)
Chrome Version 83.0.4103.106 (Official Build) (64-bit)

### Other information

It looks like it's caused by this, but I'm not sure there's any way to work around it.
https://final-form.org/docs/final-form/faq#why-does-final-form-set-my--field-value-to-undefined

I tried subscribing to the modified fields and setting any fields to "" if they were in modified but not in the values but this breaks with array fields as they appear in modified as `fieldname[1]` instead of just `fieldname`. If there's some way to get field names without them being flattened I can work around this.

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.