decaporg / decaporg/decap-cms

Empty array not being inserted with empty optional list field

Open
#2,613 5 comments 1 reaction 0 assignees View on GitHub
pinned
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

**Describe the bug**

According to #1988 and #782, optional fields should be inserted as an empty string or array. An empty string is being inserted for optional string widgets, but this is not happening for list widgets.

**To Reproduce**

Use the config below and create a new page.

**Expected behavior**

A key with an empty array should be inserted for lists when no content is added.

**Applicable Versions:**

- Netlify CMS version: 2.9.7
- Git provider: GitHub

**CMS configuration**
```yaml
backend:
name: git-gateway
branch: master
media_folder: static/media
public_folder: /media

collections:

- label: Pages
name: pages
label_singular: Page
folder: content/content
create: true
editor:
preview: false

fields:
- label: Title
name: title
widget: string

- label: Body
name: body
widget: markdown
required: false

- label: Optional Field
name: optional_field
default: ''
required: false
widget: string
hint: This has a default empty string. It will be inserted as an empty string.

- label: Sidebar
name: sidebar
widget: list
default: []

fields:
- label: Heading
name: heading
widget: string

- hint: "Displays this content in a box on the page"
label: Highlight
name: highlight
widget: boolean

- hint: "Put some sidebar text here"
label: "Block content"
name: block_content
widget: markdown
```

**Additional context**

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.