Strapi Version: 4.8.2
Operating System: macOS Monterey 12.5.11
Node Version: 16.17.1
NPM Version: 9.1.3
Yarn Version: -
I have heroSection component which has primaryButton and secondaryButton components inside. This buttons are OPTIONAL.
The problem is when I click “Save” - buttons’ fields (text and url) are displayed/generated/shown:
And since buttons’ fields are required, I now CANNOT publish the item because of the validation on these fields.
So the question is -
is it possible to have OPTIONAL component but with REQUIRED fields inside?
Or maybe the better question - is it possible for the component fields’ to NOT SHOW UP when I click save, so that I can publish the item?
Many thanks for help
Use a dynamic zone and have your component that has the required field as a component in this dynamic zone (as well as all other page components)
This should solve your validation issue, as the component if it’s not needed, just isn’t added to the dynamic zone by content editors.
Well, that works but it’s still just a workaround which… doesn’t feel right.
A dynamic zone should be used for fields for which I can fill out different kind of components.
(I use this for blog posts - user can select RichText, or Quote components for example).
But in this case, where I have optional primaryButton field, turning it into dynamic zone in which I can only select on kind of component… again… feels weird.
I don’t know if I am missing something, or it’s a Strapi bug and I should open an issue, or it’s intended behaviour (if so, it’s really weird behaviour in my opinion)
Simply, if the field is optional, I don’t see a reason why should it’s fields POP UP after saving an item.