Delete the value of an optional text/image widget results in an empty string value
- Dominant language
- JavaScript
- Stars
- 19.4k
- Forks
- 3.1k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
**Describe the bug**
If a text/image widget is ``required: false``, removing the existing value of the widget would left an empty string value, rather than ``undefined`` or ``null``.
**To Reproduce**
1. Define an optional text/image widget
```yml
fields: # The fields for each document, usually in front matter
- {label: 'Excerpt', name: 'excerpt', widget: 'text', required: false}
- {label: 'Image', name: 'photos', widget: 'image', required: false}
```
2. Create a post with the widgets edited
3. Edit the post again to delete the value of the widgets
4. The field of two widgets left in the generated markdown file with empty strings:
```markdown
excerpt: ""
photos: ""
```
**Expected behavior**
Remove the fields completely if the widget is optional and empty.
**Screenshots**
**Applicable Versions:**
- Decap CMS version: 3.1.1
**CMS configuration**
**Additional context**
This bug is issued in #995, #2007, #2848, #1449, #2017. As replied https://github.com/decaporg/decap-cms/issues/995#issuecomment-566791366, seems this bug should be fixed since 3.0.0.
Contributor guide
Assessment
This issue has not been assessed yet.