search
AI OnAI Off
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/
I would like to show a property, on a basepage that all pagetypes inherit from, but only if certain conditions are met;
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; }