I have a simple form with a label and two date pickers where the user is supposed to pick a StartDate and a EndDate. If the user selects e.g. 6/1/2040 the EndDate DatePicker should start at this given time. I have made the following:
HTML:
<RadzenLabel Text=@local[ResourcesKeys.Keys.StartDate] class="col-sm-3 col-form-label" />
<div class="col inputSpacer">
<RadzenDatePicker Disabled="@IsCurrent"
@bind-Value="ResourcePlanFormObject.StartDate"
Min="DateTime.Now"
style="width: 100%;"
ShowTime="true"
HoursStep="1"
MinutesStep="5"
TValue="DateTimeOffset?"
Kind="DateTimeKind.Local"
DateFormat="yyyy-MM-dd:hh-mm"
AllowInput="false" />
<ValidationMessage For="@(() => ResourcePlanFormObject.StartDate)" />
</div>
<RadzenLabel Text=@local[ResourcesKeys.Keys.EndDate] class="col-sm-3 col-form-label" />
<div class="col inputSpacer">
<RadzenDatePicker @bind-Value="ResourcePlanFormObject.EndDate"
style="width: 100%;"
ShowTime="true"
HoursStep="1"
MinutesStep="5"
TValue="DateTimeOffset?"
Kind="DateTimeKind.Local"
InitialViewDate="SetEndDateMinAndInitialView()"
Min="SetEndDateMinAndInitialView()"
DateFormat="yyyy-MM-dd-hh-mm"
AllowInput="false"
Change="@(() => EditContext.Validate())" />
<ValidationMessage For="@(() => ResourcePlanFormObject.EndDate)" />
</div>
C# code behind:
private DateTime? SetEndDateMinAndInitialView()
{
if (ResourcePlanFormObject.StartDate == null)
{
return DateTime.Now;
}
else
{
return ResourcePlanFormObject.StartDate.Value.DateTime;
}
}
I would assume this code should do exactly what I want but the initial date doesn't change. But if I hardcode e.g. DateTime.Now.AddMonths(5) and set it within my InitialViewDate the DatePicker displays the right start month