Try our conversational search powered by Generative AI!

Show/Hide property editors based on other property value in Content Block Editing

Vote:
 

Is it possible to make some properties of you content block only visible or enabled in Edit mode based on the value of another property?  For example, if my content type has properties

UseHeader (bool)

HeaderText (string)

HeaderBackground (custom SelectionFactoryType)

HeaderIcon (ContentReference Image selector)

Could I make the HeaderText, HeaderBackground, and HeaderIcon properties all be hidden from the Edit screen unless the "UseHeader" checkbox is selected, then those three properties appear for configuration?

#177299
Apr 06, 2017 20:15
Vote:
 

You should be able to do something like this. In this sample, MainContentArea is hidden based on the DisableProperty checkbox

[EditorDescriptorRegistration(TargetType = typeof(ContentArea))]
    public class DynamicallyHideProperty : EditorDescriptor
    {
        public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
        {
            base.ModifyMetadata(metadata, attributes);

           // Hide MainContentArea based on the setting on DisablePropertyValue setting.
            if (metadata.PropertyName == "MainContentArea")
            {
                if ((bool)metadata.FindOwnerContent().Property["DisableProperty"].Value)
                {
                    metadata.ShowForEdit = false;
                }
                
                
            }
        }
    }
#177301
Apr 06, 2017 21:11
Vote:
 

It is possible but involves some dojo tweaking: https://gregwiechec.com/2015/05/extending-all-properties-view/

#177302
Apr 06, 2017 21:11
Vote:
 

Aniket, metadata.FindOwnerContent() seems to always return null -- is there something I need to initialize first for this to work?

#177380
Apr 10, 2017 15:43
Vote:
 

What if you do metdata.OwnerContent.Property["YourPropertyName"]

#177384
Apr 10, 2017 17:16
Vote:
 

nope, OwnerContent is also null, as is Parent and Container, I am not seeing any way to retrieve a reference to anything "above" the current property.

#177385
Apr 10, 2017 17:19
Vote:
 

I think Dejan's link has provided the solution. it is better to use client technique.

#177628
Apr 14, 2017 16:14
Vote:
 

Yes, I ended up created a custom EditorDescriptor that allowed me to decrate a boolean model property with the name of the field it should be showing/hiding.  This EditorDescriptor then specified the name of a custom dojo widget class.  This dogo widget then derived from the epi checkbox widget so that when it's value changed, it would find the widget for the associated Property and do a jquery .show or .hide on that item.

#177634
Apr 14, 2017 18:58
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.