Unplanned
Last Updated: 24 Sep 2024 17:12 by Andrew
Andrew
Created on: 24 Sep 2024 11:38
Category: DateInput
Type: Bug Report
0
Min and Max parameters are ignored if the Value is DateOnly or TimeOnly

The Min and Max parameters of the DateInput, DatePicker and TimePicker don't work if the component Value is of type DateOnly or TimeOnly. Here is a test page:

<p>
    Allowed dates between @DateInputMin.ToShortDateString() and @DateInputMax.ToShortDateString(). Enter an invalid date:
</p>

Nullable DateTime (if out of range, will <strong style="color:green">nullify</strong>):
<TelerikDateInput @bind-Value="@NullableDateTimeValue"
                  Min="@DateInputMin"
                  Max="@DateInputMax"
                  Width="120px" />

@NullableDateTimeValue?.ToShortDateString()

<br />
<br />

DateTime (if out of range, will <strong style="color:green">autocorrect</strong>):
<TelerikDateInput @bind-Value="@DateTimeValue"
                  Min="@DateInputMin"
                  Max="@DateInputMax"
                  Width="120px" />

@DateTimeValue.ToShortDateString()

<br />
<br />

Nullable DateOnly (if out of range, will <strong style="color:red">accept</strong>):
<TelerikDateInput @bind-Value="@NullableDateOnlyValue"
                  Min="@DateInputMin"
                  Max="@DateInputMax"
                  Width="120px" />

@NullableDateOnlyValue?.ToShortDateString()

<br />
<br />

DateOnly (if out of range, will <strong style="color:red">accept</strong>):
<TelerikDateInput @bind-Value="@DateOnlyValue"
                  Min="@DateInputMin"
                  Max="@DateInputMax"
                  Width="120px" />

@DateOnlyValue.ToShortDateString()

@code {
    private DateTime DateTimeValue { get; set; } = DateTime.Today;
    private DateOnly DateOnlyValue { get; set; } = DateOnly.FromDateTime(DateTime.Today);

    private DateTime? NullableDateTimeValue { get; set; } = DateTime.Today;
    private DateOnly? NullableDateOnlyValue { get; set; } = DateOnly.FromDateTime(DateTime.Today);

    private DateTime DateInputMin { get; set; } = DateTime.Today.AddYears(-10);
    private DateTime DateInputMax { get; set; } = DateTime.Today;
}

1 comment
Andrew
Posted on: 24 Sep 2024 17:12

Thanks Dimo for posting this great example of the unexpected behavior, I appreciate it. Our team decided ultimately to use a [CustomDateChecker] Data Annotation code to handle our validation in order to better message to the user why the date constraints were being applied. We also figured out how to get around the DateOnly issue by just redefining that property's get; and set; functions to re-cast the data from DateOnly to DateTime and back and forth as needed, which is a decent work-around.

 

Thanks!