I am stuck with two problems related to the DateTimePicker and the DatePicker.
We have a checkbox in the view where the user can enable/disable the time selector (date only or date/time), and another checkbox for 24 hour range for which I want to disable the To Date DatePicker (have both a FromDate and ToDate pickers).
What I would like to know is..
1. How to disable/enable a DatePicker.
2. How to switch it from date to date/time and back to date again - dependent on the checkbox selection above.
Controls and script in my view. Pretty simple stuff, but my toDatePicker var does not allow me to enable/disable the control. It just does nothing.
I have not done any code yet for changing the date picker between date only and date/time. I cannot even disable the control, so not looked at this yet. Would appreciate a heads up on how to do this please.
Also open to a better way to what I have indicated below.
We have a checkbox in the view where the user can enable/disable the time selector (date only or date/time), and another checkbox for 24 hour range for which I want to disable the To Date DatePicker (have both a FromDate and ToDate pickers).
What I would like to know is..
1. How to disable/enable a DatePicker.
2. How to switch it from date to date/time and back to date again - dependent on the checkbox selection above.
Controls and script in my view. Pretty simple stuff, but my toDatePicker var does not allow me to enable/disable the control. It just does nothing.
I have not done any code yet for changing the date picker between date only and date/time. I cannot even disable the control, so not looked at this yet. Would appreciate a heads up on how to do this please.
Also open to a better way to what I have indicated below.
@Html.EditorFor(x => x.SelectByDateAndTime)
@Html.CheckBoxFor(x => x.TwentyFourHourShift)
@Html.LabelFor(x => x.DateFrom, new { id = "FromDateLabel"})
@Html.EditorFor(x => x.DateFrom)
@Html.EditorFor(m => m.DateTo)
$(document).ready(function () {
var fromDateLabel = $("#FromDateLabel");
var toDatePicker = $("#DateTo").data("kendoDateTimePicker");
var twentyFourHourShiftCheckBox = $("#TwentyFourHourShift");
var selectByDateTimeCheckBox = $("#SelectByDateAndTime");
twentyFourHourShiftCheckBox.click(function () {
if (twentyFourHourShiftCheckBox.attr('checked')) {
selectByDateTimeCheckBox.attr("disabled", true);
fromDateLabel.text("For Date");
}
else {
selectByDateTimeCheckBox.removeAttr("disabled");
fromDateLabel.text("From Date");
}
toDatePicker.enable();
});
selectByDateTimeCheckBox.click(function () {
if (selectByDateTimeCheckBox.attr('checked'))
twentyFourHourShiftCheckBox.attr("disabled", true);
else
twentyFourHourShiftCheckBox.removeAttr("disabled");
toDatePicker.enable();
});
});