static-cms
static-cms copied to clipboard
Object widgets fields is required even when the object widget itself is not required
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
.
- Create a new entry for the "Collections" collection.
- Enter a
name
and alabel
. - Inside the "files" list widget there should be one empty object. For that object, enter
file
name
andlabel
. - 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:
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.
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 😅