问题
I am initializing a datetimepicker as
$(document).ready(function() {
$("#meeting_datetime").datetimepicker({format: 'LLLL', stepping: 5, enabledHours: [], daysOfWeekDisabled: []}).prop('disabled', true);
});
Now I would like to enable this datetimepicker and limit the possible selection dynamically depending on user input. I call this function everytime the user changes certain other selections
$("#meeting_datetime").datetimepicker({defaultDate: tomorrowsDate, format: 'LLLL', enabledHours: meeting_time_moment.hours(), stepping: 5, daysOfWeekDisabled: weekday_unchecked_value}).prop('disabled', false);
The only aspect of this function which works is the disable false statement at the end. The datetimepicker does indeed become editable. However, the daysOfWeekDisabled function doesn't work at all. I am inputting something like this
weekday_unchecked_value = [0, 1, 3, 4, 5, 6]
when I do this in the initialization step (first code snipped on the top), it works fine, but the update does not seem to work. Is there a refresh function or anything? I had a look at the docs (https://eonasdan.github.io/bootstrap-datetimepicker/), but I couldn't find it...
回答1:
I found the solution... just use the functions instead
$("#meeting_datetime").data("DateTimePicker").daysOfWeekDisabled(weekday_unchecked_value)
$("#meeting_datetime").data("DateTimePicker").enabledHours([meeting_time_moment.hours()])
$("#meeting_datetime").data("DateTimePicker").stepping(60)
it seems to me that there should be an easier way, but this is quick and works fine...
来源:https://stackoverflow.com/questions/38515423/modify-datetimepicker-dynamically-with-javascript