TelerikDatePicker in blazor

6 posts, 0 answers
  1. khashayar
    khashayar avatar
    31 posts
    Member since:
    Sep 2019

    Posted 05 Dec 2019 Link to this post

    Hi, 

    i want to bind a DateTimeOffset typed property to TelerikDatePicker 
    is there any way to convert type in bind event ?
    i just want to pick date if i bind it to TelerikDateTimePicker it would work but i dont want to select time

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5018 posts

    Posted 05 Dec 2019 Link to this post

    Hi,

    If you want date selection only, you need to use the DatePicker component: https://demos.telerik.com/blazor-ui/datepicker/overview

    If you want time selection only, the TimePicker component will serve: https://demos.telerik.com/blazor-ui/timepicker/overview

    The DateTimePicker offers both: https://demos.telerik.com/blazor-ui/datetimepicker/overview

    The idea of having three separate components is so that you can get the user experience you want.

    All of them require a DateTime object in the view model, however, and you can use its setter to extract the needed information to populate your TimeSpan field. Alternatively, instead of two-way binding, you can use the events the components expose (ValueChanged and/or OnChange, see here, here and here) and do the same in the event handler.

     

    Regards,
    Marin Bratanov
    Progress Telerik

     UI for Blazor
  3. khashayar
    khashayar avatar
    31 posts
    Member since:
    Sep 2019

    Posted 05 Dec 2019 in reply to Marin Bratanov Link to this post

    i found this code 
    @result<br />

    <TelerikDatePicker ValueChanged="@( (DateTime d) => MyValueChangeHandler(d) )"></TelerikDatePicker>

    @code {

    string result;

    private void MyValueChangeHandler(DateTime theUserInput){

    result = string.Format("The user entered: {0}", theUserInput);

    }

    }

    helpfull but whe i run it i get an error

     

    System.InvalidOperationException: Telerik.Blazor.Components.TelerikDatePicker`1[System.DateTime] requires a value for the 'ValueExpression' ValueExpression is provided automatically when using 'bind-Value'.

  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5018 posts

    Posted 05 Dec 2019 Link to this post

    Hello khashayar,

    I just tested this example and it does not throw errors for me. Can you confirm you have .NET Core 3.1 RTM installed and that you have updated your Telerik UI for Blazor reference to 2.5.0? If doing so does not help, please open a support ticket and send me a project where I can observe this error. 

    Of course, you can also provide a Value to the component like in the second example in our docs, this can let you define a default value so the user won'd start in January 0001, which would be rather inconvenient for them.

     

    Regards,
    Marin Bratanov
    Progress Telerik

     UI for Blazor
  5. khashayar
    khashayar avatar
    31 posts
    Member since:
    Sep 2019

    Posted 05 Dec 2019 in reply to Marin Bratanov Link to this post

    my .Net version is 3.1.100-preview3-014645
  6. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5018 posts

    Posted 05 Dec 2019 Link to this post

    Hello Khashayar,

    Try upgrading to the .NET Core 3.1 RTM version and to Telerik UI for Blazor 2.5.0.

    Regards,
    Marin Bratanov
    Progress Telerik

     UI for Blazor
Back to Top