November Happy Hour will be moved to Thursday December 5th.

Creating a property without Label/DisplayName is impossible?

Vote:
 

Hi, i have the requirement to show some checkboxes in an inline block without a label, but the cms is adding the property-name as fallback:

This is the main block: 

public class ArticleFilterBlock : NonTrackingBlockBase
{
	[Display(
		Name = "Articles filter criteria",
		Order = 10)]
	public virtual ArticleFilterCriteriaBlock? ArticleFilterCriteria { get; set; }

	[Display(
		Name = "Visible filters",
		Order = 20)]
	public virtual ArticleFilterSettingsBlock? ArticleFilterSettings { get; set; }
}

and this is the ArticleFilterSettingsBlock

public class ArticleFilterSettingsBlock : NonTrackingBlockBase
{
	[Display(Name = "Sort by", Description = "The initial sorting of displayed Articles in the result list",
		Order = 10)]
	[SelectOne(SelectionFactoryType = typeof(EnumSelectionFactory<ArticleSortOrder>))]
	[DefaultValue(ArticleSortOrder.StartPublishDesc)]
	public virtual string? SortBy { get; set; }

	[Display(Order = 20)]
	[SelectMany(SelectionFactoryType = typeof(EnumSelectionFactory<ArticleFilterBarSettings>))]
	public virtual string? ArticleFilterBarSettings { get; set; }
}

So i want to show the ArticleFilterbarSettings without a label since it's just a bunch of checkboxes and the "Visible filters" is already the label for both properties.

It seems to be impossible :

#312129
Nov 07, 2023 16:53
Vote:
 

It's possible. You can create a custom editor to remove the label.
but if you only want to remove the label of the checkboxes, the simplest way in my opinion is creating a custom SelectMany attribute.

    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class SelectManyWithoutLabelAttribute : Attribute, IDisplayMetadataProvider
    {
        public void CreateDisplayMetadata(DisplayMetadataProviderContext context)
        {
            var extendedMetadata = context.DisplayMetadata.AdditionalValues[ExtendedMetadata.ExtendedMetadataDisplayKey] as ExtendedMetadata;
            if (extendedMetadata == null)
            {
                return;
            }

            extendedMetadata.ClientEditingClass = "epi-cms/contentediting/editors/CheckBoxListEditor";
            extendedMetadata.SelectionFactoryType = SelectionFactoryType;
            extendedMetadata.DisplayName = "";
        }
        public virtual Type SelectionFactoryType { get; set; }
    }
#312172
Nov 08, 2023 6:42
Tim Schmelter - Nov 08, 2023 11:11
Thanks, that's working. Actually if i just provide a Description the question-mark(help text) is shown and there is no label. With the SelectManyWithoutLabelAttribute the behavior is same. But once i remove also the description this attribute come in useful, no help-text and label are shown.
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.