System Library Common Episerver
Search Results for

    DocFx,SystemLibrary.Common.Episerver.Properties.MessageConfig,SystemLibrary.Common.Episerver.Properties.MessageEditorDescriptor,SystemLibrary.Common.Episerver.Properties.MessageProperty,SystemLibrary.Common.Episerver.Properties.MessageController,SystemLibrary.Common.Episerver.Attributes.BoxSelectionController,SystemLibrary.Common.Episerver.Attributes.BoxSelectionFactory,SystemLibrary.Common.Episerver.Attributes.JsonEditController,SystemLibrary.Common.Episerver.Attributes.JsonEditFactory,SystemLibrary.Common.Episerver.Descriptors.HideCategoryListDescriptor,SystemLibrary.Common.Episerver.Properties.ParentLinkReferenceController,SystemLibrary.Common.Episerver.Properties.ParentLinkReferenceEditorDescriptor,SystemLibrary.Common.Episerver.Properties.ParentLinkReferenceProperty,SystemLibrary.Common.Episerver.Attributes.MultiDropdownSelectionController,SystemLibrary.Common.Episerver.Attributes.MultiDropdownSelectionFactory,SystemLibrary.Common.Episerver.Initialize.RemoveSuggestedContentTypes,SystemLibrary.Common.Episerver.Extensions.CommonEpiserverApplicationServicesOptions,SystemLibrary.Common.Episerver.Extensions.CommonEpiserverApplicationBuilderOptions,SystemLibrary.Common.Episerver.EditController,SystemLibrary.Common.Episerver.Abstract.BaseController,SystemLibrary.Common.Episerver.Abstract.BaseMultiSelectionFactory,SystemLibrary.Common.Episerver.ConnectionStringsConfig,SystemLibrary.Common.Episerver.PropertiesConfig,SystemLibrary.Common.Episerver.EditConfig,SystemLibrary.Common.Episerver.Properties.MessageConfig,SystemLibrary.Common.Episerver.FontAwesome,SystemLibrary.Common.Episerver.AppSettings.Configuration,SystemLibrary.Common.Episerver.Attributes.ParentLinkReferenceFactory,SystemLibrary.Common.Episerver.Abstract.InternalBaseController,WebApplicationInitializer
    Show / Hide Table of Contents
    NamespaceSystemLibrary.Common.Episerver.Attributes SystemLibrary.Common.Episerver.dll

    Show a selection of items in boxes, where one can select one or more boxes

    1. Create a simple color picker with 3-4-5 colors that Editors can choose from?

    2. Choose between a few choices instead of radiobuttons/dropdownlist/checkboxes?

    BoxSelectionAttribute

    public class BoxSelectionAttribute : Attribute, IDisplayMetadataProvider, IMetadataDetailsProvider

    Inheritance
    System.Object
    BoxSelectionAttribute
    Implements
    Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.IDisplayMetadataProvider
    Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.IMetadataDetailsProvider
    Examples
    X

    Let's assume we got one enum with colors:

    enum ColorSelection {
        None,
        [EnumValue("#fff")]
        White,
        [EnumValue("#bbb")]
        Grey,
        [EnumValue("#000")]
        Black,
    }

    Select one color:

    [Display(Name = "Background Color")]
    [BoxSelection()]
    public virtual ColorSelection Color { get; set; }

    Select one color, but hide some:

    [Display(Name = "Background Color")]
    [BoxSelection(Hide = ColorSelection.Grey)]
    public virtual ColorSelection Color { get; set; }

    Select one color, but only among the ones we show:

    [Display(Name = "Background Color")]
    [BoxSelection(Show = new object[] { ColorSelection.Grey, ColorSelection.Black} )]
    public virtual ColorSelection Color { get; set; }

    Select many colors, but only among the ones we show:

    [Display(Name = "Background Color")]
    [BoxSelection(Show = new object[] { ColorSelection.Grey, ColorSelection.Black} )]
    public virtual IList<string> Colors { get; set; }
    
    //Note: Property is now a list of strings, so to get the Enum simply call Colors[0].ToEnum<ColorSelection>()

    Select many colors, but only among the ones we show and prevent unselecting all boxes:

    [Display(Name = "Background Color")]
    [BoxSelection(Show = new object[] { ColorSelection.Grey, ColorSelection.Black }, AllowUnselection = false )]
    public virtual IList<string> Colors { get; set; }
    
    //Note: Property is now a list of strings, so to get the Enum simply call Colors[0].ToEnum<ColorSelection>()

    Example with built-in FontAwesome Icons:

    enum ProductSelection 
    {
      [EnumValue(FontAwesomeSolid.hourglass)]
      Product1,
      [EnumValue(FontAwesomeSolid.house)]
      Product2
    }
    
    [BoxSelection()]
    public virtual ProductSelection Product { get; set; }

    Example with custom images:

    enum ImageSelection 
    {
     [EnumValue("")]
     Unset,
    
     [EnumValue("/static/images/blog-image.png")]
     [EnumText("")]
     Image1,
    
     [EnumValue("/static/images/article-image.png")]
     [EnumText("Optional: Text above image")]
     Image2
    }
    
    [BoxSelection(EnumType = typeof(ImageSelection))]
    public virtual string ImagePath { get; set; }
    //Optional: public virtual ImageSelection ImageSelected { get; set; }
    //If you are interested in the 'EnumValue' (url path) then chose 'string'
    Arguments
    X

    Properties

    Allow unselection of the currently selected value, leaving all options to be deselected

    - if all items are deselected, and Content is Published, the default value is then stored in the property

    - An enum has a default integer of 0 usually, a string is null

    View Source

    public bool AllowUnselection { get; set; }

    X
    Property Value
    Type Description
    System.Boolean

    Specifically set the Enum Type to be the Selection

    Not needed to be set if the EnumType is the property type, as in 'public virtual SomeEnum ...'

    View Source

    public Type EnumType { get; set; }

    X
    Property Value
    Type Description
    Type

    Hide a range of items

    By default all items are shown, unless explicit setting Hide or Show

    Hide can either be one value, or a new object[] { ... }

    View Source

    public object Hide { get; set; }

    X
    enum Colors {
        None,
        White,
        Grey,
        Black,
    }
    
    
    Show = Color.White //would then show only one item to be select, white
    
    Show = new object[] { Color.White, Color.Grey, Color.Black} //would show 3 items, would not show 'none'
    
    Hide = Color.Grey //would hide only grey, show all other options
    
    Hide = new object[] { Color.White, Color.Black } //would show only None and Grey
    X
    Property Value
    Type Description
    System.Object

    Option to set your own selection factory instead of the built-in one

    View Source

    public virtual Type SelectionFactoryType { get; set; }

    X
    Property Value
    Type Description
    Type

    Show a range of items

    By default all items are shown, unless explicit setting Hide or Show

    Show can either be one value, or a new object[] { ... }

    View Source

    public object Show { get; set; }

    X
    enum Colors {
        None,
        White,
        Grey,
        Black,
    }
    
    Show = Color.White //would then show only one item to be select, white
    
    Show = new object[] { Color.White, Color.Grey, Color.Black} //would show 3 items, would not show 'none'
    
    Hide = Color.Grey //would hide only grey, show all other options
    
    Hide = new object[] { Color.White, Color.Black } //would show only None and Grey
    X
    Property Value
    Type Description
    System.Object

    Show expired (removed/deleted) options from the Factory in the user interface for Editors

    Items no longer existing, but are still selected in the DB on some properties, will then appear as 'Expired: ...'

    Do note that if property is an Enum, and an Enum is never null, so the value stored is the INT, which then will still be sent to the 'View/Frontend' even though the Enum does not contain that number anymore
    View Source

    public bool ShowExpiredItems { get; set; }

    X

    public enum Products { A, B, C }

    A ProductBlock.cs has a property

    public virtual Products ProductSelected {get; set;} = Products.B;

    // Product B is selected/stored in DB

    Then we delete B as an option from the Enum, it's obsolete/not for sale anymore

    Products now contain only A and C

    With this option turned on, B is displayed as 'Expired: 1'

    • if property type is 'virtual string' it would show 'Expired: B'
    X
    Property Value
    Type Description
    System.Boolean

    Methods

    View Source

    public void CreateDisplayMetadata(DisplayMetadataProviderContext context)

    X
    Methods arguments
    Type Name Description
    Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DisplayMetadataProviderContext context

    Implements

    Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.IDisplayMetadataProvider
    Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.IMetadataDetailsProvider

    Extension Methods

    TExtensions.ReactServerSideRender<T>(T, Object, String, Boolean, String, String, String, Boolean, Boolean, Boolean)

    }

    • View Source
    In This Article
    Package: nuget
    Source: github
    Website: System Library Common Episerver