Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty array not being inserted with empty optional list field #2613

Open
freshyill opened this issue Aug 27, 2019 · 5 comments
Open

Empty array not being inserted with empty optional list field #2613

freshyill opened this issue Aug 27, 2019 · 5 comments
Labels

Comments

@freshyill
Copy link

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

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

@freshyill freshyill changed the title list field Empty array not being inserted with empty optional list field Aug 27, 2019
@freshyill
Copy link
Author

My temporary workaround is to put an empty default on a required field in the list.

The user will have to delete the list entry if it's not needed. This is terrible for users to have to deal with, but by having, and then removing, the item in the list, it causes an empty value to remain after it's deleted and the file is saved.

@barthc
Copy link
Contributor

barthc commented Aug 28, 2019

@freshyill default option for the list widget only works on the list field(s). Prior to PR #2374 an empty [{}] would have been automatically generated for your list widget, but that was forcing an empty field(s) for the list widget in the editor page, hence the PR.

@freshyill
Copy link
Author

Thanks! Has anyone come up with a better workaround in the meantime until this is merged? Or is what I'm doing pretty much it?

@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@erquhart
Copy link
Contributor

erquhart commented Nov 8, 2019

Related to #1407

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants