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

DateTimePicker Date ASP.NET MVC

1 Answer 22 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 24 Mar 2021, 09:01 PM

Hi Team,

I am using the below attached code for the date field. 

                      @(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.AddDays(365))
                        .Min(Model.OnsiteDtTm))

Since I am using the "DateInput()", I can change the date (Month, Day, Year, etc) from the keyboard (by pressing the arrow key). What I want to do is if I am changing the date and if the date gets prior to MIN date or later to Max date, then I want to display the "placeholder" instead of "date being automatically reset" to either MIN or MAX. For example, let's assume the MIN date is set to "12/12/2012 12:12:12 PM" and as soon as I have the date "12/12/2012 12:12:11 PM" in the date field which is less to MIN date by 1 second (assuming I am changing the date by arrow key), I want to display the placeholder. 

I am not sure how to trigger an event for the keyboard input to the date field (by changing a date by an arrow key)

Please reach out to me as soon as you can since I am working on essential project. 

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 29 Mar 2021, 11:48 AM

Hi Mayurbhai,

Based on the provided information, I would suggest handling the Change event and resetting the value there:

.Events(ev=>ev.Change("onChange"))

function onChange(e){
              var val = e.sender.value();
              var min = e.sender.options.min;
              
              if(val.getTime()==min.getTime()){
                e.sender.value(null);
                e.sender._dateInput.value(null);
              }
}

Let me know if additional information is needed.

 

Regards,
Tsvetomir
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
Tsvetomir
Telerik team
Share this question
or