Repository navigation
Fail required validation when a Content Blocks property has no blocks - #105
Merged
PerplexDaniel merged 1 commit intoSep 28, 2026
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #104.
Problem
Ticking Mandatory on a
Perplex.ContentBlocksproperty never produces a validation error, so a page publishes with zero blocks.Umbraco's
RequiredValidatortreats aJSON-typed value as empty only when it isnullor when the string collapses to{}or[](StringExtensions.JsonEmpties). AContentBlocksValueis a versioned envelope —{"version":4,"header":null,"blocks":[]}— which matches neither, so the required check always passes.ContentBlocksValidatordoes not cover it either, since it only walks the properties inside each existing block.Change
ContentBlocksRequiredValidatornormalises an empty value to{}and defers to the base validator, andContentBlocksValueEditoroverridesRequiredValidatorto return it. This follows Umbraco's ownRichTextRequiredValidator, which normalises a rich text value the same way before delegating.A value counts as empty when it has no header and no blocks. Values that fail to deserialise are passed through untouched, so malformed data keeps the current behaviour rather than being reported as empty.
Verification
Ran
ValidateRequiredagainst the new validator and the stockRequiredValidatorfor the same inputs, on net10.0 against Umbraco 17. The stock column is the current behaviour.#validation_invalidEmptynull#validation_invalidNull#validation_invalidNulldotnet buildonPerplex.ContentBlocks.Core: 0 warnings, 0 errors withTreatWarningsAsErrorson.Notes
ContentBlocksValueDeserializer.DeserializerunsRefine, which drops blocks whose element type no longer exists. A property holding only such blocks therefore validates as empty. That seemed right, since those blocks render nothing, but say the word if you would rather the check ran on the raw value.ContentBlocksValidatoralready performs. Happy to thread a shared value through instead if you prefer.RELEASE_NOTES.md, since the version this lands in is yours to decide.