0

I'm trying to get initialized my DateTimepicker with multiple Dates. 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:

  • with setDate an a array of Dates and Strings
  • with date and multiple Strings or multiple Dates as Strings
  • directly over the value attribut of the input field

Does someone has an idea?

Mike
  • 4,041
  • 6
  • 20
  • 37
Dominik
  • 1
  • 2
  • I dont think its supported, ive created a feature request https://github.com/tempusdominus/bootstrap-4/issues/226 . I am currently looking into the source code to see if I can find some sort of a hack – Flame Jan 03 '19 at 12:54

1 Answers1

0

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.

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);
}
Flame
  • 6,663
  • 3
  • 33
  • 53
  • It throws a "TypeError: oldDate is undefined" error when the Clear button is clicked. – kag Feb 23 '19 at 03:35
  • You'll have to debug that further yourself. Possibly it is missing some other setting. – Flame Feb 24 '19 at 14:15