Netlify-cms: Boolean is shown as required even though it has a default

Created on 24 Feb 2020  路  7Comments  路  Source: netlify/netlify-cms

Describe the bug
When you setup a boolean field, and have other fields that are required, the boolean shows an error message even though it has a default.

To Reproduce

  1. Create a boolean widget
  2. Create an input widget.
  3. Create a new entry, fill nothing in, click Publish.
  4. Notice the UI tells you both fields are required
  5. Fill in the input widget
  6. Press publish
  7. Notice bool still shows error
  8. Turn bool on, turn bool back off
  9. Press publish, notice it saves now.

Expected behavior
I shouldn't have to turn a bool from false(default), to true, to false

Screenshots
image

Applicable Versions:

  • Netlify CMS version: 2.10.26
  • Git provider: github
  • OS: Mac
  • Browser version Chrome 80.0

  • Node.JS version: 10.17.0

CMS configuration

backend:
  name: git-gateway
  branch: master

media_folder: static/img/content
public_folder: /img/content

collections:
  - name: 'blog'
    label: 'Blog'
    format: 'json'
    folder: 'assets/content/blog'
    create: true
    slug: '{{slug}}'
    editor:
      preview: false
    fields:
      - label: 'Published'
        name: 'isPublished'
        widget: 'boolean'
      - label: 'Icon'
        name: 'icon'
        widget: 'select'
        options: ['VUE', 'NUXT']
      - label: 'Publish Date'
        name: 'date'
        widget: 'datetime'
      - label: 'title'
        name: 'title'
        widget: 'string'
      - label: 'Description'
        name: 'description'
      - label: 'thumb'
        name: 'thumb'
        widget: 'object'
        fields:
          - label: 'Url'
            name: 'url'
            widget: 'image'
            media_library:
              config:
                multiple: false
          - label: 'Alt'
            name: 'alt'
      - label: 'Body'
        name: 'body'
        widget: 'list'
        types:
          - label: 'Code Block'
            name: 'codeBlock'
            widget: 'object'
            fields:
              - label: 'Title'
                name: 'title'
              - label: 'Style'
                name: 'style'
                widget: 'select'
                options: ['GOOD', 'BAD', 'NORMAL']
                default: 'NORMAL'
              - label: 'Code'
                name: 'code'
                widget: 'markdown'
          - label: 'Image'
            name: 'image'
            fields:
              - label: 'Url'
                name: 'url'
                widget: 'image'
              - label: 'Alt'
                name: 'alt'
                widget: 'string'
          - label: 'Markdown'
            name: 'markdown'
            fields:
              - label: 'Content'
                name: 'content'
                widget: 'markdown'
          - label: 'YouTube Video'
            name: 'youTubeVideo'
            fields:
              - label: 'ID'
                name: 'id'
                widget: 'string'
docs extensionwidgets

Most helpful comment

Ah so the default in the docs is really only used when the field isn't required. Otherwise the default really doesn't qualify as filled for required fields.. :)

I think just some tweaks in the docs would be fine for now.

All 7 comments

Same thing here

The boolean field in this configuration doesn't have a default field. I tried adding default: false to it and it works.
@brunetton, can you share your config?

@erezrokah The docs say the default is already false, so we shouldn't need to set 'default'

image

Hmm, I see the issue now, thank you for clarifying.
The phrasing for string is similar:
image

Does it mean that not having a default value for a required string field should allow you to have empty strings?
Not really, but in the case of boolean fields it is confusing since we don't have a good way to show missing values at the moment.

Not having a default value for a required field means a user must set that field's value before saving.
We'll need to figure out a way to clearly communicate that for the boolean widget

Ah so the default in the docs is really only used when the field isn't required. Otherwise the default really doesn't qualify as filled for required fields.. :)

I think just some tweaks in the docs would be fine for now.

Thanks to both of you, adding a default value to false solves the problem. The doc should really be clarified, in all tickets I've participated this was the conclusion :)
Thanks !

LOL, such a simple change, but a world of difference. Thanks @erezrokah !

Was this page helpful?
0 / 5 - 0 ratings