How to select values from popup list serveral times in MultiSelect Dropdown control?

Hello Syncfusion Team,

I'd like to know if there is an easy way to select identical values from the popup list several times within the MultiSelect control?

My use case would be to use this dropdown control as sort of expression editor for formulas with predefined items (which can be selected several times) originated from the popup list and dynamically added values based on AllowCustomValue setting to true. When I try to add an clone of an already selected item with identical text value, but let's say different Id which would be OK for my scenario, with AddItemsAsync when OnChipTag event fires, this is only working when AllowCustomValue is set to false. Then I could tag this items as cloned item and would remove them again from value list when OnValueRemove event fires. But as I said, AddItemsAsync unfortunately not working in this scenario.

Please refer to my sample code snippet attached to this post.

Can you help me with my issue? Thanks a lot in advance for your support.


Best regards,

Florian


Attachment: ExpressionEditor_4138845.zip


5 Replies

FL Florian January 28, 2022 07:33 PM UTC

Hello Support Team,

any news about my question? Appreciate your help, thank you!

Best regards,

Florian



SP Sureshkumar P Syncfusion Team January 31, 2022 12:50 PM UTC

Florian, 
 
we have modified the sample, Based on your shared sample code example with your requirement. The duplicate value added by addItem button click method in the no-record template value. duplicate value (added by AddItems method) is not listed once selected in the input element. So, we need to filter the same value again to select added duplicate ID values. 
 
Find the modified code here: 
<div class="container-fluid"> 
    <div class="col-4"> 
        <SfMultiSelect @ref="formulaMultiSelect" TValue="int[]" TItem="TechnicalParameter" Placeholder="Define formula" DataSource="@technicalParameters" AllowCustomValue=true AllowFiltering="true" Mode="@VisualMode.Box"> 
            <MultiSelectFieldSettings Text="Name" Value="ID" /> 
            <MultiSelectEvents TValue="int[]" TItem="TechnicalParameter" OnChipTag="@OnChipTag" OnValueRemove="@OnValueRemove" CustomValueSpecifier="@CustomValueSpecifier" Filtering="@CustomFilter" /> 
            <MultiSelectTemplates TItem="TechnicalParameter"> 
                    <NoRecordsTemplate> 
                        <div> 
                            <div id="nodata">No matched item, would you like to add it to the list as a new item?</div> 
                            <SfButton id="btn" class="e-control e-btn custom-button" @onclick="@AddItem">Add New Item</SfButton> 
                        </div> 
                    </NoRecordsTemplate> 
                </MultiSelectTemplates> 
        </SfMultiSelect> 
    </div> 
</div> 
 
<style> 
    .e-chips.expression, .e-chips.expression:hover { 
        background-color: darkblue; 
    } 
    .e-chips.operator, .e-chips.operator:hover { 
        background-color: orange; 
    } 
</style> 
 
@code { 
    private SfMultiSelect<int[], TechnicalParameter>? formulaMultiSelect; 
    private int cloneId = 1000; 
    private string Custom { get; set; } 
    Random rnd = new Random(); 
 
    private ObservableCollection<TechnicalParameter> technicalParameters = new ObservableCollection<TechnicalParameter> 
    { 
        new TechnicalParameter() { ID = 1, Name = "IntParam1", Description = "First int parameter", DataType = typeof(int).ToString(), Quantity = 15 }, 
        new TechnicalParameter() { ID = 2, Name = "IntParam2", Description = "Second int parameter", DataType = typeof(int).ToString(), Quantity = 20 }, 
        new TechnicalParameter() { ID = 3, Name = "+", Description = "+ operator", DataType = typeof(string).ToString(), Quantity = float.MinValue, IsOperator = true }, 
        new TechnicalParameter() { ID = 4, Name = "-", Description = "- operator", DataType = typeof(string).ToString(), Quantity = float.MinValue, IsOperator = true } 
    }; 
 
    private void CustomFilter(FilteringEventArgs args) 
    { 
        this.Custom = args.Text; 
    } 
 
    private async Task OnChipTag(TaggingEventArgs<TechnicalParameter> args) 
    { 
        args.SetClass = args.ItemData.IsOperator ? "operator" : "expression"; 
        //await formulaMultiSelect.AddItemsAsync(new ObservableCollection<TechnicalParameter> { new TechnicalParameter() { ID = cloneId++, Name = args.ItemData.Name, Description = args.ItemData.Description , DataType = args.ItemData.DataType, Quantity = args.ItemData.Quantity, IsClone = true, IsOperator = args.ItemData.IsOperator }}); 
    } 
 
    private void CustomValueSpecifier(CustomValueEventArgs<TechnicalParameter> args) 
    { 
        double res = 0; 
 
        // Allow only numeric values 
        if (!double.TryParse(args.Text, out res)) 
            args.Cancel = true; 
    } 
 
    private async Task AddItem( Object sender) 
    { 
        var customData = new TechnicalParameter() { ID  = rnd.Next(cloneId), Name = this.Custom }; 
        await this.formulaMultiSelect.AddItems(new ObservableCollection<TechnicalParameter> { customData }); 
        technicalParameters.Add(customData); 
        await this.formulaMultiSelect.HidePopupAsync(); 
    }  
 
    private void OnValueRemove(RemoveEventArgs<TechnicalParameter> args) 
    { 
        if (args.ItemData.IsClone) 
            technicalParameters.Remove(args.ItemData); 
    } 
 
 
    private class TechnicalParameter 
    { 
        public int ID { get; set; } 
        public string? Name { get; set; } 
        public string? Description { get; set; } 
        public string? DataType { get; set; } 
        public float Quantity { get; set; } 
        public bool IsClone { get; set; } 
        public bool IsOperator {get; set; } 
    } 
} 
 
 
Regards, 
Sureshkumar P 



FL Florian January 31, 2022 09:55 PM UTC

Hello,

thanks a lot for your reply, but your sample isn't working properly! If I use the button "Add new item" within the NoRecordsTemplate, all previous selected items within the control will be deleted and the newly added item isn't selected properly. So up to now I still cannot achieve what I want, please refer to this screenshot:

MultiSelectIdenticalItems.jpg

I'd like to add/select and chip multiple identical items from a predefined List (DataSource) and user-defined custom values. I'm still a step further (like you can see) but not at the end of the journey. I still have problems to handle custom values properly.

Can you please re-check this issue. Thanks again for your help.


Regards,
Florian



VJ Vinitha Jeyakumar Syncfusion Team February 1, 2022 01:26 PM UTC

Hi Florian,


Currently, we are validating your reported query. we will update you the further details in two business days on or before 3rd February 2022.

Regards,
Vinitha


SP Sureshkumar P Syncfusion Team February 4, 2022 03:01 PM UTC

Florian, 
 
By default, the component hideselecteditem property is in true. That is the reason once your selected item is not in the listed element in popup. So, we suggest you added new items showcase once you filter the value in the multiselect input element. Also, your condition in the CustomValueSpecifier allows only double data type values. That is the reason you cannot be able to add other type data inside your multiselect component.  
 
Regards, 
Sureshkumar P 


Loader.
Up arrow icon