decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.93k stars 3.04k forks source link

Fields marked optional are still required #315

Closed techpeace closed 7 years ago

techpeace commented 7 years ago

- 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

techpeace commented 7 years ago

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

biilmann commented 7 years ago

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

erquhart commented 7 years ago

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

luczaki114 commented 6 years ago

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

tech4him1 commented 6 years ago

@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!

xavibenjamin commented 6 years ago

I'm having this same issue

https://github.com/smithtimmytim/brightlycolored.org/blob/master/admin/config.yml

tech4him1 commented 6 years ago

@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.

xavibenjamin commented 6 years ago

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

snimavat commented 6 months ago

required:false for image field doesnt work

- { label: "Featured Image", name: "thumbnail", widget: "image", required:false }

Still, UI requires the field