Hello,
I have a multi-select dropdown of countries.
Instead of "6 selected"
I would like to have "6 countries selected"
How do I achieve that?
Hi Pavel,
We can achieve the requested requirement using JSInterop and OnValueSelect, ValueRemoved events. Please refer to the below code snippet and sample for more details.
[index.razor]
|
@using Syncfusion.Blazor.DropDowns @using System.Runtime.InteropServices @inject IJSRuntime JSRuntime
<SfMultiSelect TValue="List<string>" TItem="Country" CssClass="@((MultiVal != null && MultiVal.Count > 0) ? VALUE_IS_PRESENT_CSS_CLASS : FILTER_DEFAULT_CSS_CLASS)" Placeholder="Countries" EnableChangeOnBlur="false" @bind-Value="@MultiVal" DataSource="@Countries" Mode="@VisualMode.CheckBox" ShowClearButton="true" AllowFiltering="false" PopupHeight="700px" PopupWidth="400px" Width="200px"> <MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings> <MultiSelectEvents TValue="List<string>" TItem="Country" ValueChange="@ValueChanged" Created="@OnCreated" OnValueSelect="@OnValueSelecthandler" ValueRemoved="@ValueRemovedhandler"></MultiSelectEvents> </SfMultiSelect> @code { private async Task ValueRemovedhandler(RemoveEventArgs<Country> args) { await JSRuntime.InvokeAsync<object>("ChnageText"); } private async Task OnValueSelecthandler(SelectEventArgs<Country> args) { await JSRuntime.InvokeAsync<object>("ChnageText"); } } |
[Script]
|
function ChnageText() { setTimeout(function () { var el = document.getElementsByClassName('e-remain')[0]; if (el != null) { var myArray = el.innerHTML.split(" "); el.innerHTML = myArray[0] + " Countries " + myArray[1]; } },50); } |
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp1_4-519981220
Kindly try the above suggestion and let us know if this meets your requirement.
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Regards,
Udhaya Kumar D
Hello this solution works partly but when you click away from the multiselect,
the text goes back to the default "3 selected" instead of "3 countries selected"
I have attached a video recording of the issue.
Thank you
Attachment: Screen_Recording_20220928_at_12.20.41_PM_4bbb5f85.zip
Hi Pavel,
We can resolve the reported issue by calling the ‘ChnageText’ function in the blur event of the component. Please refer to the below sample for more details.
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp1_41166733089
Documentation : https://blazor.syncfusion.com/documentation/multiselect-dropdown/events#blur
Kindly try the above suggestion and let us know if this meets your requirement.
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Udhaya Kumar D
Great thank you! I have two more questions:
e-remainI have added a video reference
Thank you
Attachment: Screen_Recording_20220929_at_4.10.47_PM_e7f5efba.zip
Hi Pavel,
Query 1 :
How can I get this to work with 2 multi-selects on 1 page. this part of the code targets a common property
e-remain
By changing the below highlighted property we can able to modify the required MultiSelect component as per the requirement. Please refer to the below sample for more details.
|
var el = document.getElementsByClassName('e-remain')[0]; |
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp1_41580220517
Query 2 :
Is there any way to get rid of the flicker seen every-time you focus away from the multi-select? Even no values are selected or deselected
We have achieved the requested requirement at the sample level. We can’t change the e-remain before it appends in the DOM. So we have used a condition to check whether the e-remain is available or not. Based on that we have modified the e-remain class. So, the flicker will occur.
Udhaya Kumar D
Query 1 :
How can I get this to work with 2 multi-selects on 1 page. this part of the code targets a common property
e-remain
____
This is still not working for me. I implemented the code a seen in the sample but the code is unpredictable. As selection of one multiselect will change the text on the other multiselect even though i changed the array like the sample.
var el = document.getElementsByClassName('e-remain')[1];
Please refer to screen recording and the code sample.
Thank you
Hi Pavel,
We are validating the requirement. We will update the further details in two business days (7th October 2022).
Udhaya Kumar D
Hi Pavel,
We have created a sample to resolve the above-reported conflict and shared it below for reference. Please refer to the below sample for more details.
[Index.razor]
|
@using Syncfusion.Blazor.DropDowns @using System.Runtime.InteropServices @inject IJSRuntime JSRuntime
<SfMultiSelect ID="multi1" TValue="List<string>" TItem="Country" CssClass="sample1" Placeholder="Countries" EnableChangeOnBlur="false" @bind-Value="@MultiVal" DataSource="@Countries" Mode="@VisualMode.CheckBox" ShowClearButton="true" AllowFiltering="false" PopupHeight="700px" PopupWidth="400px" Width="200px"> <MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings> <MultiSelectEvents TValue="List<string>" TItem="Country" Blur="BlurHandler" ValueChange="@ValueChanged" Created="@CreatedHandler1"></MultiSelectEvents> </SfMultiSelect>
<hr /> <SfMultiSelect ID="multi2" TValue="List<string>" TItem="Country" CssClass="sample2" Placeholder="Countries" EnableChangeOnBlur="false" @bind-Value="@MultiVal2" DataSource="@Countries" Mode="@VisualMode.CheckBox" ShowClearButton="true" AllowFiltering="false" PopupHeight="700px" PopupWidth="400px" Width="200px"> <MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings> <MultiSelectEvents TValue="List<string>" TItem="Country" Blur="BlurHandler2" ValueChange="@ValueChanged2" Created="@CreatedHandler2"></MultiSelectEvents> </SfMultiSelect>
@code { private const string FILTER_DEFAULT_CSS_CLASS = "defaultClass"; private const string VALUE_IS_PRESENT_CSS_CLASS = "selectedClass"; public List<string> MultiVal { get; set; } = new List<string>() { }; public List<string> MultiVal2 { get; set; } = new List<string>() { }; public int multi1_SelectedItem; public int multi2_SelectedItem; protected override void OnInitialized() { MultiVal = new List<string>() { "AU", "CA" }; } private void CreatedHandler1(Object args) { ValueChanged(new MultiSelectChangeEventArgs<List<string>> { Value = MultiVal }); } private void CreatedHandler2(Object args) { ValueChanged2(new MultiSelectChangeEventArgs<List<string>> { Value = MultiVal2 }); } private async Task BlurHandler(Object args) { await JSRuntime.InvokeAsync<object>("ChnageText", multi1_SelectedItem); } private async Task ValueChanged(MultiSelectChangeEventArgs<List<string>> arg) { multi1_SelectedItem = (arg.Value == null) ? 0 : arg.Value.Count; await JSRuntime.InvokeAsync<object>("ChnageText", multi1_SelectedItem);
} private async Task ValueChanged2(MultiSelectChangeEventArgs<List<string>> arg) { multi2_SelectedItem = (arg.Value == null) ? 0 : arg.Value.Count; await JSRuntime.InvokeAsync<object>("ChangeText2", multi2_SelectedItem);
}
private async Task BlurHandler2() { await JSRuntime.InvokeAsync<object>("ChangeText2", multi2_SelectedItem); } } |
[script.js]
|
function ChnageText(x) { var el = document.getElementsByClassName('e-delim-values e-delim-view')[0]; if (x == 0) { el.innerHTML = " "; } else { if (el.classList.contains('e-delim-hide')) { el.classList.remove('e-delim-hide'); } el.innerHTML = x + " Countries Selected" } } function ChangeText2(y) { var el = document.getElementsByClassName('e-delim-values e-delim-view')[1]; if (y == 0) { el.innerHTML = " "; } else { if (el.classList.contains('e-delim-hide')) { el.classList.remove('e-delim-hide'); } el.innerHTML = y + " Countries Selected" } } |
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Regards,
Udhaya Kumar D
Hello, when I try to implement the code
I get "3 countries selected +3 more..."
Any way to prevent the e-remain class from displaying "+3 more..."
Hi Pavel,
We have validated the reported query on our end. Unfortunately, we couldn’t reproduce the reported issue as per your scenario. We have shared a video illustration for reference. Also, we request you to provide additional details about the issue as mentioned below, This will help us validate the issue further and provide you with a better solution.
1. Issue reproducing sample (or modify the previously shared sample as per your scenario).
2. Issue replication steps.
3. Video illustration of the issue.
Regards,
Udhaya Kumar D
I have attached a sample and a video recording identifying two issues:
2. When user clicks away and then selects and deselects a value text show +3 more..
Hi Pavel,
We are validating the requirement. We will update the further details in two business days (14th October 2022).
Udhaya Kumar D
Hi Pavel,
Sorry for the inconvenience caused.
By using the setTimeout function in the JSInterop we can solve the reported issue. Please refer to the below code snippet for more details.
|
function ChnageText(x) { setTimeout(function () { var el = document.getElementsByClassName('e-delim-values e-delim-view')[0]; if (x == 0) { el.innerHTML = " "; } else { if (el.classList.contains('e-delim-hide')) { el.classList.remove('e-delim-hide'); } el.innerHTML = x + " Countries Selected" } }, 100); } |
Regards,
Udhaya Kumar D