Skip to content

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

@hangvane

Description

@hangvane

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}
  1. Create a post with the widgets edited
  2. Edit the post again to delete the value of the widgets
  3. 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:

  • Decap CMS version: 3.1.1

CMS configuration

Additional context

This bug is issued in #995, #2007, #2848, #1449, #2017. As replied #995 (comment), seems this bug should be fixed since 3.0.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugcode to address defects in shipped code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions