diff --git a/Havit.Blazor.Components.Web.Bootstrap.Documentation/XmlDoc/Havit.Blazor.Components.Web.Bootstrap.xml b/Havit.Blazor.Components.Web.Bootstrap.Documentation/XmlDoc/Havit.Blazor.Components.Web.Bootstrap.xml index 7747f313..dc9b6c58 100755 --- a/Havit.Blazor.Components.Web.Bootstrap.Documentation/XmlDoc/Havit.Blazor.Components.Web.Bootstrap.xml +++ b/Havit.Blazor.Components.Web.Bootstrap.Documentation/XmlDoc/Havit.Blazor.Components.Web.Bootstrap.xml @@ -4261,11 +4261,16 @@ Input-group at the end of the input. - + Text to display in the input instead of a list of selected values. + + + Selects the value to be displayed in the input instead of a list of selected values. + + Input-group at the end of the input. diff --git a/Havit.Blazor.Components.Web.Bootstrap/Forms/HxMultiSelect.cs b/Havit.Blazor.Components.Web.Bootstrap/Forms/HxMultiSelect.cs index 15b80e5e..ca584216 100644 --- a/Havit.Blazor.Components.Web.Bootstrap/Forms/HxMultiSelect.cs +++ b/Havit.Blazor.Components.Web.Bootstrap/Forms/HxMultiSelect.cs @@ -97,13 +97,19 @@ public class HxMultiSelect : HxInputBase>, IInputWit /// /// Text to display in the input instead of a list of selected values. /// - [Parameter] public string Text { get; set; } + [Parameter] public string InputText { get; set; } + + /// + /// Selects the value to be displayed in the input instead of a list of selected values. + /// + [Parameter] public Func, string> InputTextSelector { get; set; } /// /// Input-group at the end of the input. /// [Parameter] public RenderFragment InputGroupEndTemplate { get; set; } + private List itemsToRender; private HxMultiSelectInternal hxMultiSelectInternalComponent; @@ -169,7 +175,7 @@ protected override void BuildRenderInput(RenderTreeBuilder builder) builder.OpenComponent>(100); builder.AddAttribute(101, nameof(HxMultiSelectInternal.InputId), InputId); builder.AddAttribute(102, nameof(HxMultiSelectInternal.InputCssClass), GetInputCssClassToRender()); - builder.AddAttribute(103, nameof(HxMultiSelectInternal.InputText), !string.IsNullOrEmpty(Text) ? Text : CurrentValueAsString); + builder.AddAttribute(103, nameof(HxMultiSelectInternal.InputText), GetInputText()); builder.AddAttribute(104, nameof(HxMultiSelectInternal.EnabledEffective), EnabledEffective); builder.AddAttribute(105, nameof(HxMultiSelectInternal.ItemsToRender), itemsToRender); builder.AddAttribute(106, nameof(HxMultiSelectInternal.TextSelector), TextSelector); @@ -189,6 +195,21 @@ protected override void BuildRenderInput(RenderTreeBuilder builder) builder.CloseComponent(); } + private string GetInputText() + { + if (!string.IsNullOrEmpty(InputText)) + { + return InputText; + } + else if (InputTextSelector is null || Data is null || CurrentValue is null) + { + return CurrentValueAsString; + } + + var currentItems = Data.Where(i => CurrentValue.Contains(SelectorHelpers.GetValue(ValueSelector, i))); + return SelectorHelpers.GetValue(InputTextSelector, currentItems); + } + /// protected override string FormatValueAsString(List value) {