Hi - I have a question that could maybe be answered in a couple of different ways. I have a user group that likes the date time picker but wants to easily enter the TIME component as military time without a colon.
The user picks a date and then immediately wants to enter a 4-digit value for the time (e.g. 1342). The code below works, but if they use the keyboard and the date picker (alt-down, arrows to choose date, then enter) they have to manually highlight the "hh:mm" value (time-consuming). If this could be auto-selected when a date was selected via the picker, that would be ideal.
Also, I have not been able to ONLY have a format of HHmm set. When I do this, the validation always throws errors. I suspect this is because there *needs* to be some kind of separator between the hour and minute, but am not sure. I have tried various combinations of getting that to work, and have gotten all the way to a "save" button click and into the controller code (ASP.NET MVC 5), but the date field is always null.
I think if I could just get the time part to auto-select when the user chooses a date, that would answer my needs best. But I would be curious about your thoughts on the time part being formatted as just HHmm without a colon separator and how I could get that to work.
I have this attribute on my model field:
I have this code in Razor on the view:
I have this code in $.document.ready():
The user picks a date and then immediately wants to enter a 4-digit value for the time (e.g. 1342). The code below works, but if they use the keyboard and the date picker (alt-down, arrows to choose date, then enter) they have to manually highlight the "hh:mm" value (time-consuming). If this could be auto-selected when a date was selected via the picker, that would be ideal.
Also, I have not been able to ONLY have a format of HHmm set. When I do this, the validation always throws errors. I suspect this is because there *needs* to be some kind of separator between the hour and minute, but am not sure. I have tried various combinations of getting that to work, and have gotten all the way to a "save" button click and into the controller code (ASP.NET MVC 5), but the date field is always null.
I think if I could just get the time part to auto-select when the user chooses a date, that would answer my needs best. But I would be curious about your thoughts on the time part being formatted as just HHmm without a colon separator and how I could get that to work.
I have this attribute on my model field:
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy HH:mm", ApplyFormatInEditMode = true)]
I have this code in Razor on the view:
@(Html.Kendo().DateTimePickerFor(model => model.MyDateTimeField).Format("MM/dd/yyyy HH:mm").TimeFormat("HH:mm").ParseFormats(new[] { "MM/dd/yyyy HH mm", "MM/dd/yyyy HHmm", "MM/dd/yyyy HH:mm" }))
I have this code in $.document.ready():
$.validator.addMethod('date',
function (value, element) {
return this.optional(element) || kendo.parseDate(value);
});