umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.53k stars 2.7k forks source link

Single Block Mode forces fields to be mandatory #17309

Open MiguelGuedelha opened 1 month ago

MiguelGuedelha commented 1 month ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.5.1

Bug summary

The purpose of Single Block Mode is to help the Models Builder in giving us a single block item (for building fields which are meant to have only a single block item, and not many, such as adding a single re-usable Widget block to many pages, for example)

However, such single blocks, don't always necessarily need to exist on a page, they could be optional.

The current configuration of a block list in single mode requires the following settings:

When such a block list gets added to a document type as a field, it will cause the field to essentially become mandatory / you won't be able to save the page unless a block of the given list type is added to the document.

Is there a design decision somewhere that prevents the following configuration from also making ModelsBuilder generate a BlockListItem\<T> with an empty list returning default(T)?

The mandatory/optional nature of the field would then instead be controlled by the document that uses it.

Thoughts? The current way it works essentially renders Single Block Mode useless unless the fields it is going to be used are always mandatory by nature of the document type anyways.

Specifics

No response

Steps to reproduce

  1. Have a default site installation with ModelsBuilder set to SourceCodeAuto
  2. Create a Element/block document type, can be anything
  3. Create a Block List data type that uses said Element type as its only allowed type and enable single block mode + make max amount 1 and minimum amount 1
  4. Create a document type (not an element), with a single property that uses said block list as it's editor, leave it as optional, make it so it can be created as a root component
  5. A model will be created with the property set as type BlockListItem\<T>
  6. Create said document in the content tree and give it a name.
  7. Try to save the document, it won't allow to save, even though the property is optional
  8. Modify the created block list data type to have a minimum of 0 elements instead a. Leaving single block mode enabled or not at this point is irrelevant but try any steps after this with both
  9. Save the block list type and go back to the document in the content tree
  10. The document will not be save-able without the property being filled in
  11. The generated model will however revert back to a BlockListModel, instead of being BlockListItem\<T>

Expected result / actual result

  1. Have a default site installation with ModelsBuilder set to SourceCodeAuto
  2. Create a Element/block document type, can be anything
  3. Create a Block List data type that uses said Element type as its only allowed type and enable single block mode + make max amount 1 and minimum amount 1
  4. Create a document type (not an element), with a single property that uses said block list as it's editor, leave it as optional, make it so it can be created as a root component
  5. A model will be created with the property set as type BlockListItem\<T>
  6. Create said document in the content tree and give it a name.
  7. Try to save the document, it won't allow to save, even though the property is optional
  8. Modify the created block list data type to have a minimum of 0 elements instead a. Leave single block mode turned on
  9. Save the block list type and go back to the document in the content tree
  10. The document will now be save-able without the property being filled in
  11. The generated model remains a BlockListItem\<T>, but when the value is empty in a given page/document in the CMS, the property will have default(T) as it's value when processing the ModelsBuilder generated model of the page
github-actions[bot] commented 1 month ago

Hi there @MiguelGuedelha!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

NguyenThuyLan commented 3 weeks ago

Thank @MiguelGuedelha , very detail issue information. I was able to reproduce this on v15.0.0-rc2.