Completed
Last Updated: 24 Jan 2024 12:50 by ADMIN
Release 2.23.0
Robert
Created on: 20 Feb 2020 09:16
Category: DatePicker
Type: Bug Report
4
Deleting the date with the keyboard when bound to non-nullable DateTime leaves incorrect validation messages and state after a valid date is selected

Delete the input, choose a date from the dropdown. The issue is that the first picker remains invalid, while it is valid, a keyboard interaction with the input is required to clear the invalid state.

Reproducible:

@using System.ComponentModel.DataAnnotations;

    <EditForm Model="ModelData">
        <DataAnnotationsValidator />
        <ValidationSummary />
        <br /><br />
        <span>Not nullable</span> @ModelData.Date<br />
        <Telerik.Blazor.Components.TelerikDatePicker @bind-Value="ModelData.Date" Min="DateTime.MinValue" Max="DateTime.MaxValue"></Telerik.Blazor.Components.TelerikDatePicker><br /><br />
        <span>Nullable</span> @ModelData.Date2<br />
        <Telerik.Blazor.Components.TelerikDatePicker @bind-Value="ModelData.Date2" Min="DateTime.MinValue" Max="DateTime.MaxValue"></Telerik.Blazor.Components.TelerikDatePicker><br /><br />
    </EditForm>

@code  {

    public MyModel ModelData { get; set; }

    protected override void OnInitialized()
    {
        ModelData = new MyModel();
    }

    public class MyModel
    {
        public string Name { get; set; }

        [Required(ErrorMessage = "Non nullable required")]
        public DateTime Date { get; set; } = DateTime.Today;

        [Required(ErrorMessage = "Nullable required")]
        public DateTime? Date2 { get; set; } = DateTime.Today;
    }
}

4 comments
ADMIN
Svetoslav Dimitrov
Posted on: 24 Jan 2024 12:50

Hello David,

The Required DataAnnotation attribute works with nullable data types. When the DatePicker is bound to a non-nullable DateTime object the Required attribute is never triggered. This attribute is only valid when the value becomes null. 

To fire the [Required] attribute you can bind the DatePicker to a nullable DateTime object.

Regards,
Svetoslav Dimitrov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
David
Posted on: 17 Jan 2024 17:54

I am still experiencing this issue in version 5.0.1. 

Are there instructions available on how I can override this error message? It seems to take precedence over all the DataAnnotation decorations.

ADMIN
Svetoslav Dimitrov
Posted on: 23 Feb 2021 12:41

Hello,

For the time being, you can use the Nullable DateTime object (DateTime?) as a workaround. Let us know if you keep experiencing the same issue when using nullable DateTime.

Regards,
Svetoslav Dimitrov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

ADMIN
Marin Bratanov
Posted on: 01 May 2020 07:22

Hi Robert,

This one somehow fell through the cracks when updating statuses, I think we fixed it for 2.9.0 as part of the following one so I am marking this as a duplicate: https://feedback.telerik.com/blazor/1456610-unexpected-years-validation-behavior-on-keyboard-input. If you keep having issues with this, let's look into them further.

 

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.