Won't Fix
Last Updated: 31 Mar 2020 09:10 by ADMIN
Scheduled for 2.10.0
Boštjan
Created on: 27 Mar 2020 08:10
Category: DropDownList
Type: Bug Report
4
DropDownList does not select the first Value in its data source

Before, the Value from the first item in the Data was populated through @bind-Value to the view model. It no longer is.

In the following snippet, I expect to see "1" in the initial load of the page, but I see "0" - the default value for the integer.

@selectedValue

<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" @bind-Value="@selectedValue">
</TelerikDropDownList>

@code {
    //in a real case, the model is usually in a separate file
    //the model type and value field type must be provided to the dropdpownlist
    public class MyDdlModel
    {
        public int MyValueField { get; set; }
        public string MyTextField { get; set; }
    }

    IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });

    int selectedValue { get; set; }
}

3 comments
ADMIN
Marin Bratanov
Posted on: 31 Mar 2020 09:10

Hello Boštjan,

We have been reviewing this and we have found that the old behavior was never correct - the dropdownlist should not select the first item in the dropdown. It should be up to the application to determine what values are allowed and our old behavior was wrong. We will be aligning ours with the native InputSelect and the standard ways this is handled. You can preview the documentation about this here: https://github.com/telerik/blazor-docs/commit/79b2c24fbc3b71fc4e9afad5f271c879de38199b.

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
ADMIN
Marin Bratanov
Posted on: 27 Mar 2020 08:18

And here is a workaround

@selectedValue

<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" @bind-Value="@selectedValue">
</TelerikDropDownList>

@code {
    //in a real case, the model is usually in a separate file
    //the model type and value field type must be provided to the dropdpownlist
    public class MyDdlModel
    {
        public int MyValueField { get; set; }
        public string MyTextField { get; set; }
    }

    IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });

    int selectedValue { get; set; }

    protected override void OnInitialized()
    {
        // workaround - set the value to the first item manually
        // this is done in OnInitialized for brevity, do it after fetching the data for the first time
        selectedValue = myDdlData.FirstOrDefault().MyValueField;

        base.OnInitialized();

    }
}

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
ADMIN
Marin Bratanov
Posted on: 27 Mar 2020 08:15

Indeed, this seems to have broken in 2.9.0, and seems to work in 2.8.0

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.