Hi Team,
I am using the DateTimePicker and below is the code.
@(Html.Kendo()
.DateTimePicker()
.ComponentType("modern")
.Name("dpLTSummaryCompletionDate")
.HtmlAttributes(new { style = "width: 185px;"} )
.Events(e => e.Change("dpLTSummaryCompletionDate_change"))
.Value(Model.CompletionDtTm)
.Format("MM/dd/yyyy h:mm:ss tt")
.ParseFormats(new string[] { "MM/dd/yyyy h:mm:ss tt" })
.DateInput(true)
.Max(Model.TakenDtTm.AddYears(1))
.Min(Model.OnsiteDtTm))
//In the Jquery file
$(document).on('keydown keyup', '#dpLTSummaryCompletionDate ', function () {
let dateTimePicker = $("#dpLTSummaryCompletionDate").data("kendoDateTimePicker");
let dateInput = dateTimePicker._dateInput;
let input = dateInput.value().getTime();
let min = dateTimePicker.min().getTime();
let max = dateTimePicker.max().getTime();
if (input < min || input > max) {
dateInput.value(null);
}
});
I have the "keydown keyup" event in the .js file. It seems like the ".getTime()" value for the first time I enter the date by keyboard into the date field is not the same as I get it from the second time and onwards.
For example, I have set up the Min and Max date, and I want to allow a user to enter any date between and including Min and Max dates. However, right now for the first time I enter the date, it allows only Min but not Max since ".getTime()" values for the Max date and user input (assuming user enters the max date) are not the same. As a result, the below condition gets true and date field gets null/empty.
NOTE - It allows me to enter the max date from the second time and onwards, but not the first time because ".getTime()" values are the different for the "Max()" date and the date I enter even though I enter the same Max date.
if (input < min || input > max) {
dateInput.value(null);
}
Please help me out on this since I am having issue and could not resolve.
Best,
Mickey