static-cms icon indicating copy to clipboard operation
static-cms copied to clipboard

Object widgets fields is required even when the object widget itself is not required

Open Skrubbadubba opened this issue 2 years ago • 2 comments

Description This happens to me sometimes, but not always. Based on some other behavior I observed with empty lists, my guess is that something triggers the object (don' know what, perhaps something to do with collapsing it) corresponding to the widget to be created. Once created, its fields cannot be left empty as the default for required is true, and thus the entry cannot be published.

Expected behaviour If required: false and the object widget is left empty in the UI during creation, the entry should be created without raising the validation error toast and it should not contain the object (or at least an empty object).

Steps to reproduce Here is what I'm working on: https://github.com/Skrubbadubba/static-cms-self-config. It's not a MRE for this particular bug, but it's minimal enough to be good for debugging. Clone it and run npm install && npm run dev && npx @staticcms/proxy-server.

  1. Create a new entry for the "Collections" collection.
  2. Enter a name and a label.
  3. Inside the "files" list widget there should be one empty object. For that object, enter file name and label.
  4. Publish the entry

These should be all the fields that do not have required: false

config.yml

I am not using yaml, but instead js and json. The relevant objects are in config/collections/metaCollection/collections.js, however the entire config object is console logged, it is probably easier to look through it there. screenshot: image

Skrubbadubba avatar Jan 22 '23 13:01 Skrubbadubba

I'll update the docs to clarify this, but the object widget only validates it has a value when required: true. When required is false, it skips that check, BUT child widgets marked as required still get validated. This is why you are seeing this behavior.

There does seem to be a bug here around the collapsed state, so I will address that here shortly. However getting required:f false to work as you want (skip child widget validation), that will require more work/time. Marking this as an enhancement.

KaneFreeman avatar Jan 23 '23 19:01 KaneFreeman

There does seem to be a bug here around the collapsed state, so I will address that here shortly. However getting required:f false to work as you want (skip child widget validation), that will require more work/time. Marking this as an enhancement.

I did some testing here and it appears this is working as expected. Only issue I found was the collapsed prop not working 😅

KaneFreeman avatar Jan 23 '23 19:01 KaneFreeman