How to show/hide properties in the CMS block editor

 

I have created a new block which contains a table allowing people to enter fields they want to appear in the view. They select the type while they do this and one of the types in 'DropDown'. While entering what fields they would like they also have the option to add select options. I only want the select options part to appear when they have select the type 'DropDown'. The documentation around this on the Episerver site is not great and only mentions how to edit out the box blocks not custom built ones.

enter image description here

So when field type is anything other than 'DropDown' I do not want the 'Select Options' part to appear. Is this possible?

#200421 Jan 11, 2019 12:56
  • David Knipe
    Member since: 2008
     

    Hello James

    I think this post might be what you are looking for: https://gregwiechec.com/2018/03/hide-tabs-and-properties-in-edit-mode/

    David

    #200426 Jan 11, 2019 13:21
  •  

    Hi David,

    Thanks for the link. Have had a look and it mentions using ShowPropertyWhenValueEquals. Do you happen to know which library this method comes from? Epi doesnt seem to know it.

    Thanks, James

    #200428 Jan 11, 2019 14:59
  •  

    Have installed the nuget package and the hide and show methods dont seem to work

    #200431 Jan 11, 2019 15:55
  •  

    David does the following look okay to you?

    [Display(
    Name = "Field type",
    Description = "Type of the field.",
    GroupName = SystemTabNames.Content,
    Order = 30)]
    [CultureSpecific]
    [BackingType(typeof(PropertyNumber))]
    [Enum(typeof(FieldTypes))]
    [HidePropertyWhenValueEquals(nameof(SelectOptions), FieldTypes.Button)]
    [HidePropertyWhenValueEquals(nameof(SelectOptions), FieldTypes.CheckBox)]
    [HidePropertyWhenValueEquals(nameof(SelectOptions), FieldTypes.CountryDropDown)]
    [HidePropertyWhenValueEquals(nameof(SelectOptions), FieldTypes.Email)]
    [HidePropertyWhenValueEquals(nameof(SelectOptions), FieldTypes.Phone)]
    [HidePropertyWhenValueEquals(nameof(SelectOptions), FieldTypes.Text)]
    [HidePropertyWhenValueEquals(nameof(SelectOptions), FieldTypes.TextArea)]
    public virtual FieldTypes Type { get; set; }

    [Display(
    Name = "Select options",
    GroupName = SystemTabNames.Content,
    Order = 60)]
    [EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<DropDownListModel>))]
    [CultureSpecific]
    public virtual IList<DropDownListModel> SelectOptions { get; set; }

    #200435 Jan 11, 2019 16:49