modify datetimepicker dynamically with javascript

点点圈 提交于 2020-01-07 02:51:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!