[英]tempusdominus 4 multiselect population
I'm trying to get initialized my DateTimepicker with multiple Dates. 我正在尝试使用多个日期初始化DateTimepicker。 I can initalized with a specific date but not with the multiple option.
我可以指定一个特定日期,但不能使用多个选项。
var selectedDates = ["12/1/2019","11/1/2019"];
$(function () {
$('#holidayPicker').datetimepicker({
format: 'L',
allowMultidate: true,
multidateSeparator: ' ',
minDate: "<?php echo $startDate->format('Y-m-d');?>",
maxDate: "<?php echo $endDate->format('Y-m-d');?>",
// setDate: [new Date(2019, 0, 4),new Date(2019, 0, 5)]
useCurrent: false,
//date: new Date(2019, 0, 4),
setDate: selectedDates,
});
});
What i have already tried: 我已经尝试过的
Does someone has an idea? 有人有主意吗?
I have managed to find a function in the source code that allows you to set the date directly. 我设法在源代码中找到一个函数,该函数可让您直接设置日期。 You have to access the datetimepicker object directly in order to use it.
您必须直接访问datetimepicker对象才能使用它。
Code snippet: 程式码片段:
var $el = ('#your-element');
// Initialize datepicker.
$el.datetimepicker({
inline: true,
format: 'DD-MM-YYYY',
allowMultidate: true,
useCurrent: false // Prevents selection of current date
});
// Get the object directly from the data attribute.
// @see https://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/
var prefill = ['01-15-2019', '01-16-2019'];
var plugin = $el.data('datetimepicker');
for(let i = 0; i < prefill.length; i++) {
// Set the dates as active. You can optionally pass your own moment object as the first argument.
plugin.date(prefill[i], i);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.