EditorDescriptor for property of type bool not quite right

I would like to show a property, on a basepage that all pagetypes inherit from, but only if certain conditions are met;

  1. Never show on a StartPage
  2. Show only if a property value on StartPage is a certain value ( e g  SiteTheme.SpecialTheme)

If I omit TargetType in EditorDescriptorRegistration, the site breaks at initialization.

I got the visibility on the condition(s) to work, but the property is shown as a TextBox, so I added the ClientEditingClass.

This makes the property show as a Checkbox, but when clicking the box, the value is set to "on" (string) instead of true/false, resulting in an exception and alert message in CMS.

Is there a more proper way to show a property of type bool depending of a condition?  I have mostly seen examples with Select Lists.

Using latest CMS 12

 

Thanks!

 

[EditorDescriptorRegistration(TargetType = typeof(bool), UIHint = "MyCustomHint")]
[EditorDescriptorRegistration(TargetType = typeof(bool?), UIHint = "MyCustomHint")]
public class HidePropertyButForTheme : EditorDescriptor
{
    private readonly IContentLoader _contentLoader;

    public HidePropertyButForTheme(IContentLoader contentLoader)
    {
        _contentLoader = contentLoader;
        ClientEditingClass = "dijit/form/CheckBox"; // without this, property shows as an empty TextBox
    }

    public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
    {
        base.ModifyMetadata(metadata, attributes);

        var contentMetadata = (ContentDataMetadata)metadata;
        var ownerContent = contentMetadata.OwnerContent;
            
        if ((ownerContent as StartPage) != null)
        {
            metadata.ShowForEdit = false;
            return;
        }

        var startPage = _contentLoader.Get<StartPage>(SiteDefinition.Current.StartPage);
        var isSpecialTheme = startPage.SiteTheme == Enums.SiteTheme.SpecialTheme;

        if (!isSpecialTheme)
        {
            metadata.ShowForEdit = false;
        }
    }
}
[UIHint("MyCustomHint")]
public virtual bool SpecialProperty { get; set; }
#343694
Edited, Oct 28, 2026 9:48
Vote:

I managed to do it using a MetadataExtender instead using code sample from Allan!

https://www.codeart.dk/blog/2022/11/property-dependency-in-optimizely-episerver-cms-12/

#343698
Oct 28, 2026 10:36
Allan Thraen - Oct 31, 2026 10:32
Awesome that you could use that old post!
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.