decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.66k stars 3.02k forks source link

Delete the value of an optional text/image widget results in an empty string value #7120

Open hangvane opened 4 months ago

hangvane commented 4 months ago

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
    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:
    excerpt: ""
    photos: ""

Expected behavior

Remove the fields completely if the widget is optional and empty.

Screenshots

Applicable Versions:

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.