Netlify-cms: Fields marked optional are still required

Created on 21 Mar 2017  路  8Comments  路  Source: netlify/netlify-cms

- Do you want to request a feature or report a bug?

Report a bug.

- What is the current behavior?

Marking a field as optional in the config.yml does not make the field optional.

- If the current behavior is a bug, please provide the steps to reproduce.

  1. Add optional: true to a field for a collection in config.yml:
collections:
  - name: "blog" # Used in routes, e.g. /admin/collections/blog
    label: "The Voxable Voice" # Used in the UI
    folder: "source/blog" # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    slug: "{{year}}-{{month}}-{{day}}-{{slug}}.html.markdown" # Filename template i.e. YYYY-MM-DD-title.md
    fields: # The fields for each document, usually in front matter
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Tags", name: "tags", widget: "string"}
      - {label: "Header Image", name: "header_image", widget: "image"}
      - {label: "Twitter Image", name: "twitter_image", widget: "image", optional: true}
      - {label: "Share Description", name: "share_description", widget: "string"}
      - {label: "Author", name: "author", widget: "string"}
      - {label: "Body", name: "body", widget: "markdown"}

- What is the expected behavior?

The field should be optional when creating a post.

- What is the actual behavior?

The field is still required:

image

- Please mention your node.js, and operating system version.

node version: 6.9.5
OS: Mac OS X 10.12.3

Using Middleman

docs discussion

Most helpful comment

Required field validation is documented here. Opened a PR to update the example config.

All 8 comments

While the optional option isn't listed in the documentation, it does appear in the example app.

Yeah, it's something we need to decide on.

In the early prototype of the CMS, we used the optional: true flag to mark a field as optional. In the current version when @cassiozen implemented validations, he mimicked the general behavior of HTML form validations, and optional fields are marked using required: false.

I personally think optional: true makes more sense when being required is the default, but it would be a change that would require updating existing config files

Required field validation is documented here. Opened a PR to update the example config.

Required: false doesn't seem to work for relation widgets. Maybe I'm missing something?

@luczaki114 It's working for me 馃槙. If you can reach out in our Spectrum Chat with a repo link or example, I'd be happy to look at it!

@smithtimmytim Can you reach out in our Gitter chat since this issue is already closed? Also, it looks like there is a typo on the required setting for your body field, maybe that is causing it.

This had to do with a service worker cache issue, not the CMS. All fixed now. Big thanks to @talves for the help.

Was this page helpful?
0 / 5 - 0 ratings