This is a migrated thread and some comments may be shown as answers.

nullable dto gets selected

4 Answers 536 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
khashayar
Top achievements
Rank 1
Veteran
khashayar asked on 03 Feb 2020, 12:48 PM

Hello,

i found an issue in TelerikDropDownList 
when you bind TelerikDropDownList value to a nullable property after data is loaded it selects the first one as the value 
but when property is not nullable and its bound to value of TelerikDropDownList  when data is read it wont select any value 
which seems reverse 

and also i might not want to select anything at all and let user leave this property empty since its nullable

and also it would be good to have DefaultText for TelerikDropDownList  but i cant use it seems unknown to TelerikDropDownList  

4 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 03 Feb 2020, 12:59 PM

Hi Khashayar,

The DropDownList already has a DefaultText parameter: https://docs.telerik.com/blazor-ui/components/dropdownlist/overview#examples

It also shows correct behavior when the Value has the default value for its type (null for the string - which is nullable, and 0 for the integer). Could you start out from that sample and see if you are facing any issues? If yes, please post here a simple runnable modification of that snippet so I can take a look.

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor
0
khashayar
Top achievements
Rank 1
Veteran
answered on 03 Feb 2020, 02:44 PM

actually i cant use DefaultText instead there is DefaultItem which i have no use for it 
DefaultText  is like an unknown property for DropDown

and this is the error 

Error: System.InvalidOperationException: Object of type 'Telerik.Blazor.Components.TelerikDropDownList`2 .... does not have a property matching the name 'DefaultText'.





and for the issue

   <EditForm OnSubmit="Save" Model="FormData" >
        <TelerikDropDownList Data="@NamesList" TextField="FirstName" ValueField="Id" @bind-Value="@FormData.MyNameId">
        </TelerikDropDownList>

        <TelerikDropDownList Data="@NamesList" TextField="FirstName" ValueField="Id" @bind-Value="@FormData.MyNullableNameId">
        </TelerikDropDownList>
        <TelerikButton ButtonType="@ButtonType.Submit">submit</TelerikButton>
    </EditForm>

@code {

    public FormModel FormData = new FormModel();

    List<Names> NamesList= (Enumerable.Range(1, 20).Select(x => new Names { Id = Guid.NewGuid(), FirstName = "jon" + Guid.NewGuid() })).ToList();

    public class Names
    {
        public Guid Id { get; set; }
        public string FirstName { get; set; }
    }

    public class FormModel
    {
        public Guid MyNameId { get; set; }
        public Guid? MyNullableNameId { get; set; }
    }

    void Save()
    {

    }


try the code above and hit submit button without choosing any value you will see the nullable property gets filled while not nullable property is 0

 

0
Accepted
Marin Bratanov
Telerik team
answered on 03 Feb 2020, 02:56 PM

Hi Khashayar,

Please upgrade to the latest version (2.7.0 at the moment) and try this again https://docs.telerik.com/blazor-ui/upgrade/overview

If an issue persists after following the current documentation (using DefaultText and validation), with the latest version, let me know.

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor
0
khashayar
Top achievements
Rank 1
Veteran
answered on 03 Feb 2020, 04:14 PM
thanks my problem is solved
Tags
DropDownList
Asked by
khashayar
Top achievements
Rank 1
Veteran
Answers by
Marin Bratanov
Telerik team
khashayar
Top achievements
Rank 1
Veteran
Share this question
or