Search code examples
jquerytwitter-bootstrapbootstrap-datetimepicker

defaultDate and minDate with Bootstrap Datetimepicker


I want a picker to be set to a month in the future by default. This works fine:

<script type="text/javascript">
  $(function () {
    $('#enddatepicker').datetimepicker({
      defaultDate: moment().add(1, 'M').toDate(),
      locale: 'de',
      format: 'DD.MM.YYYY'
    });
  });
</script>

However, I also want the date to be not before tomorrow. So I try adding a minDate option:

<script type="text/javascript">
  $(function () {
    $('#enddatepicker').datetimepicker({
      minDate: moment().add(1, 'd').toDate(),
      defaultDate: moment().add(1, 'M').toDate(),
      locale: 'de',
      format: 'DD.MM.YYYY'
    });
  });
</script>

However, now the default date is set to minDate (that is, tomorrow). Can I set a default date independently from the minimum date?


Solution

  • Looking at the code on GitHub (line 1674) if you set the option useCurrent to false, your default may not be overridden:

     <script type="text/javascript">
       $(function () {
         $('#enddatepicker').datetimepicker({
           useCurrent: false,
           minDate: moment().add(1, 'd').toDate(),
           defaultDate: moment().add(1, 'M').toDate(),
           locale: 'de',
           format: 'DD.MM.YYYY'
         });
       });
     </script>