This is a migrated thread and some comments may be shown as answers.

DateTimePicker ASP.NET MVC

1 Answer 36 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Mayurbhai
Top achievements
Rank 1
Veteran
Mayurbhai asked on 26 Mar 2021, 02:22 PM

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

1 Answer, 1 is accepted

Sort by
0
Georgi Denchev
Telerik team
answered on 29 Mar 2021, 03:07 PM

Hello, Mickey,

I left a response in the other thread:

https://www.telerik.com/forums/kendo-datetimepicker-asp-net-mvc-ui 

Let me know if further assistance is required.

Best Regards,
Georgi Denchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Date/Time Pickers
Asked by
Mayurbhai
Top achievements
Rank 1
Veteran
Answers by
Georgi Denchev
Telerik team
Share this question
or