Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 345
P_S Avatar asked Jul 31 '15 13:07

P_S


1 Answers

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>
like image 154
philreed Avatar answered Oct 14 '22 10:10

philreed