From 036042d2084ad1d1b6b14000546241a73561df72 Mon Sep 17 00:00:00 2001 From: Robert Haken Date: Tue, 28 Mar 2023 17:35:34 +0200 Subject: [PATCH] fixes #508 [HxCheckboxList] Default chip generation is unreasonable --- BlazorAppTest/Pages/InputsTest.razor | 9 +++++++ .../Havit.Blazor.Components.Web.Bootstrap.xml | 9 +++++++ .../XmlDoc/Havit.Blazor.Components.Web.xml | 2 +- .../Forms/HxCheckboxList.cs | 27 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/BlazorAppTest/Pages/InputsTest.razor b/BlazorAppTest/Pages/InputsTest.razor index 9dc478b5..09b145ef 100644 --- a/BlazorAppTest/Pages/InputsTest.razor +++ b/BlazorAppTest/Pages/InputsTest.razor @@ -81,6 +81,15 @@ + + + Submit 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 351fa57e..11b64fd5 100644 --- 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 @@ -3336,6 +3336,15 @@ Throws NotSupportedException - giving focus to an input element is not supported on the HxCheckboxList. + + + + + + + + + Displays a read-only value in the form control visual (as .form-control, with label, border, etc.).
diff --git a/Havit.Blazor.Components.Web.Bootstrap.Documentation/XmlDoc/Havit.Blazor.Components.Web.xml b/Havit.Blazor.Components.Web.Bootstrap.Documentation/XmlDoc/Havit.Blazor.Components.Web.xml index 3d09d9cd..f1276742 100644 --- a/Havit.Blazor.Components.Web.Bootstrap.Documentation/XmlDoc/Havit.Blazor.Components.Web.xml +++ b/Havit.Blazor.Components.Web.Bootstrap.Documentation/XmlDoc/Havit.Blazor.Components.Web.xml @@ -53,7 +53,7 @@ Starts the debouncing.
debouncing delay - work to be executed + work to be executed ( gets canceled if the method is called again)
diff --git a/Havit.Blazor.Components.Web.Bootstrap/Forms/HxCheckboxList.cs b/Havit.Blazor.Components.Web.Bootstrap/Forms/HxCheckboxList.cs index ffbff0e5..c4cc832a 100644 --- a/Havit.Blazor.Components.Web.Bootstrap/Forms/HxCheckboxList.cs +++ b/Havit.Blazor.Components.Web.Bootstrap/Forms/HxCheckboxList.cs @@ -137,6 +137,7 @@ protected override void BuildRenderInput(RenderTreeBuilder builder) builder.AddAttribute(51, nameof(HxCheckbox.ValidationMessageMode), Havit.Blazor.Components.Web.Bootstrap.ValidationMessageMode.None); builder.AddAttribute(52, nameof(HxCheckbox.Inline), this.Inline); + builder.AddAttribute(53, nameof(HxCheckbox.GenerateChip), false); builder.AddMultipleAttributes(100, this.AdditionalAttributes); @@ -179,4 +180,30 @@ public override ValueTask FocusAsync() throw new NotSupportedException($"{nameof(FocusAsync)} is not supported on {nameof(HxCheckboxList)}."); } + /// + protected override string FormatValueAsString(List value) + { + // Used for CurrentValueAsString (which is used for the chip generator). + if ((!value?.Any() ?? true) || (Data == null)) + { + // don't care about chip generator, it does not call this method for null/empty value + return String.Empty; + } + + // Take itemsToRender because they are sorted. + List selectedItems = itemsToRender.Where(item => value.Contains(SelectorHelpers.GetValue(ItemValueSelector, item))).ToList(); + return String.Join(", ", selectedItems.Select(ItemTextSelector)); + } + + /// + protected override bool ShouldRenderChipGenerator() + { + return CurrentValue?.Any() ?? false; + } + + /// + protected override List GetChipRemoveValue() + { + return new List(); + } } \ No newline at end of file