Describe the bug
Ticking Mandatory on a property using the Perplex.ContentBlocks editor never produces a validation error, however empty the property is. The property saves and publishes with zero blocks.
Steps to reproduce
- Add a
Perplex.ContentBlocks property to a document type and tick Mandatory.
- Create a page and add no blocks.
- Save and publish — it succeeds, with no validation message on the property.
Cause
Umbraco's RequiredValidator treats a JSON-typed value as empty only when it is null or when the string collapses to {} or [] (StringExtensions.JsonEmpties). An untouched Content Blocks property is a versioned envelope — {"version":3,"header":null,"blocks":[]} — which matches neither, so the required check always passes.
ContentBlocksValueEditor does not override DataValueEditor.RequiredValidator, and ContentBlocksValidator only walks the properties inside each existing block, so with zero blocks it yields no validation models.
For comparison, Umbraco's own Block List keeps the contract client-side: umbBlockListPropertyEditor.component.js sets vm.model.value = {} when the value is not an object, which is exactly what JsonEmpties matches, so Mandatory works there.
Verified on Umbraco 13.14.0 with Perplex.ContentBlocks 3.0.1. RequiredValidator is unchanged on Umbraco's v17 branch, and on this repo's current main ContentBlocksValueEditor still overrides only ToEditor/FromEditor, so 4.x looks the same.
Suggested fix
Either collapse an empty value to {} as the core block editors do, or override RequiredValidator on ContentBlocksValueEditor. Umbraco has a precedent for the second in RichTextRequiredValidator, which normalises the value and defers to the base:
public override IEnumerable<ValidationResult> ValidateRequired(object? value, string? valueType)
=> base.ValidateRequired(IsEmptyEnvelope(value) ? "{}" : value, valueType);
Since the configuration editor exposes no minimum-blocks setting, Mandatory is currently the only way to require content in the property.
Describe the bug
Ticking Mandatory on a property using the
Perplex.ContentBlockseditor never produces a validation error, however empty the property is. The property saves and publishes with zero blocks.Steps to reproduce
Perplex.ContentBlocksproperty to a document type and tick Mandatory.Cause
Umbraco's
RequiredValidatortreats aJSON-typed value as empty only when it isnullor when the string collapses to{}or[](StringExtensions.JsonEmpties). An untouched Content Blocks property is a versioned envelope —{"version":3,"header":null,"blocks":[]}— which matches neither, so the required check always passes.ContentBlocksValueEditordoes not overrideDataValueEditor.RequiredValidator, andContentBlocksValidatoronly walks the properties inside each existing block, so with zero blocks it yields no validation models.For comparison, Umbraco's own Block List keeps the contract client-side:
umbBlockListPropertyEditor.component.jssetsvm.model.value = {}when the value is not an object, which is exactly whatJsonEmptiesmatches, so Mandatory works there.Verified on Umbraco 13.14.0 with Perplex.ContentBlocks 3.0.1.
RequiredValidatoris unchanged on Umbraco's v17 branch, and on this repo's currentmainContentBlocksValueEditorstill overrides onlyToEditor/FromEditor, so 4.x looks the same.Suggested fix
Either collapse an empty value to
{}as the core block editors do, or overrideRequiredValidatoronContentBlocksValueEditor. Umbraco has a precedent for the second inRichTextRequiredValidator, which normalises the value and defers to the base:Since the configuration editor exposes no minimum-blocks setting, Mandatory is currently the only way to require content in the property.