Search code examples
phpbootstrap-4tempus-dominus-datetimepicker

tempus dominus pre select multidate from value attribute


I'm able to select multiple dates, then save it to database. When reading back from DB, the value attribute of the input field has all previously selected dates in it:

<input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker1" value="2019-06-18,2019-06-17,2019-06-19"/>

When the page is loading you can see all 3 briefly listed, but then only 1st one remains and the other 2 disappear.

fiddle

$(function() {
 $('#datetimepicker1').datetimepicker({
    allowMultidate: true,
    multidateSeparator: ',',
    format: 'YYYY-MM-DD'
 });
});

Solution

  • try this:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.css" rel="stylesheet"/>
    <input type="text" class="form-control datetimepicker-input" id="datepicker"/>
    <script>
        $('#datepicker').datepicker({
      multidate: true
    });
    </script>