DropDown multiple returning wrong values

I made a brand new project and I am still having a problem where setting the selected value of the drop down to a single value will show two values selected. To demonstrate the problem more easily, I have added an ordinary html select element to the page. By clicking in the html select, you can see that you are only selecting a single value at a time, but the RadzenDropDown will return 2 values even though only one is chosen. There is also an H2 that outputs the selected items.

It only happens when you the values that are selected are in the even or odd position.

@page "/test"

<h3>DropDownTest</h3>

<RadzenDropDown class="w-100"
                TValue="IEnumerable<Guid>"
                @bind-Value="@selectedIds"
                Multiple="true"
                Data="@customers"
                TextProperty="CompanyName"
                ValueProperty="CustomerID"
                Change="@RadzenDropDownChange"/>

    <select class="form-select" @onchange="HtmlSelectChanged" multiple>
        @foreach (var employee in customers)
        {
            <option value="@employee.CustomerID">@employee.CompanyName</option>
        }
    </select>

<h2>
    @foreach (var id in selectedIds)
    {
        <div>@id</div>
    }
</h2>

@code {
    List<Customer> customers = new List<Customer>();
    IEnumerable<Guid> selectedIds = new List<Guid>();

    protected override void OnInitialized()
    {
        for (int i = 0; i < 10; i++)
        {
            customers.Add(new Customer(i));
        }
    }
    
    void HtmlSelectChanged(ChangeEventArgs e)
    {
        Console.WriteLine($"{nameof(HtmlSelectChanged)}");
        if (e.Value is not null)
        {
            var what = (string[])e.Value;
            selectedIds = what.Select(Guid.Parse).ToList();
        }
    }

    void RadzenDropDownChange(object value)
    {
        Console.WriteLine($"{nameof(RadzenDropDownChange)}");
        var str = value is IEnumerable<object> ? string.Join(", ", (IEnumerable<object>) value) : value;

        Console.WriteLine($"Value changed to {str}");
    }


    public class Customer
    {
        public Guid CustomerID { get; set; }
        public string CompanyName { get; set; }

        public Customer(int id, string? companyName = null)
        {
            CustomerID = Guid.Parse($"{id}0000000-0000-0000-0000-000000000000");
            CompanyName = companyName ?? $"Company{id}";
        }
    }

}

Here is what I see from your example when I select single item:

Did you click each item? It is only every other one that has the problem.

image

We were able to reproduce the problem and we will do our best to provide fix in our next update before the end of the week.

1 Like