Datepicker not recognizing value change when format is different

Hello, I want to use the radzen datepicker component in my project. However, it turned out the datepicker does not update when I change the format of the year. Let's say I change the year 2025 to just 25 then the datepicker does not recognize it and thinks the value has not changed. Manually rerendering is not an option because it causes other problems.

<RadzenDatePicker Name="@(Name + "input" + GUID)"
Style=@($"{getTextStyle()}")
class="@(DatePickerDC.ButtonVisible ? "form-control qsc-textbox-input":"form-control qsc-textbox-input hide-calendar-icon")"
@bind-Value=@DisplayValue
Disabled="@ProtectedOnDisplay"
@onfocusin="setFocusToggler"
@onfocusout="setFocusToggler"
ShowCalendarWeek="@(DatePickerDC.ShowCalendarWeeks ? true : false)"
ShowSeconds=false
DateFormat="@RadzenDateFormat"
Culture="@(CALENDAR_ISO ? null : new System.Globalization.CultureInfo("en-US"))">

<RadzenButton Click=@(args =>
{
DisplayValue = DateTime.Now;
StateHasChanged();
}) Text="Heute" Style="width: 40%; display: inline-block;" class="rz-my-4" />
<RadzenButton Click=@(async args =>
{
DisplayValue = null;
StateHasChanged();
}) Text="Keines" Style="width: 40%; display: inline-block;" class="rz-my-4" />


public DateTime FieldValue
{
get
{
return DatePickerDC.Value;
}
set
{
DatePickerDC.Value = value;
}
}
public DateTime? DisplayValue
{
get
{
return FieldValue == nullDate ? null : FieldValue;
}
set
{
if (value == null)
{
FieldValue = nullDate;
}
else
{
var newVal = new DateTime(value.Value.Year, value.Value.Month, value.Value.Day);
FieldValue = newVal;
}
}
}

The DatePicker value is DateTime, not string - if the DateTime is the same nothing will be changed.

Hello, thanks for your response. I get that but is there some workaround? Because we have fields for short and long dates in our application and that's not very user-friendly to keep it like that

The only way is new DateTime different from the previous value.

I am considering to have my own input field and use only the datepicker popup but not sure if that will work out

There is a ParseInput func that can be used to provide your own parsing:

i will take a look, thank you

should this work when I change just the year or do I have to reenter the whole date in order to be validated correctly?

The callback is executed no matter what you've changed. For example deleting the first two digits of the year:


will result in:

1 Like

What I am ultimately trying to achieve is this: if a user enters a long date into a short date field I want it to be validated to a short one and vica versa. In addition, I want all types of formats to work, that's why I am currently using DateFormat property

DateFormat property is used for display purposes only. I already provided all the information you need to handle your case.