Hello,
I have a 2 date pickers. I have a button that clears all fields in my form which works when the dates are fully filled, but not if they are partially filled. I want to clear them with my button and not have to use the ShowClearButton (x button) that is built into the date picker. Not sure if there is already a solution for this, but I could not find one.
Below is a screenshot of the partially filled. I believe when it's partially filled, it is considered "null" still because the value isn't actually saved.
The date picker values are tied to an object "email pay". I'm trying to use ClearObject.ResetProperties(emailPay); to clear the fields. It will work if the date is completely filled (i.e. 12/12/25).
Currently the way I've had to solve this is by manually setting the values to a full date and then setting them back to null.
emailPay.InvoiceDate = DateTime.Now;
emailPay.InvoiceDueDate = DateTime.Now;
await Task.Delay(1);
emailPay.InvoiceDate = null;
emailPay.InvoiceDueDate = null;
I was just curious if there was a more elegant solution than just manually resetting it.
<TelerikDatePicker @bind-Value="@DateToClear" ShowWeekNumbers="true" Format="MM/dd/yy"> </TelerikDatePicker> <button @onclick="ClearField">Clear Field</button> <button @onclick="MyCurrentFix">Clear Field Hacky Way</button> @code { DateTime? DateToClear {get; set;} = null; //This only works if the date is partially filled (fill only part of date picker so it gives error) private void ClearField() { DateToClear = null; StateHasChanged(); } // currently the fix that I have below, but it's really hacky (this can clear partially filled dates) private async Task ResetDate() { DateToClear = DateTime.Now; await Task.Delay(1); DateToClear = null; } private async Task MyCurrentFix() { await ResetDate(); StateHasChanged(); } }