Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable future dates in Bootstrap 3 Datetimepicker

I'm using Bootstrap 3 Datetimepicker and I need to disable all my future dates, I know it has it's own disabledDates function but I tried so many times and it's still not working.

What am I doing wrong?

$('#data_move').datetimepicker({
    language: 'pt-BR',
    disabledDates: [
        moment("22/02/2017")
    ]
});
like image 210
MattDAVM Avatar asked Nov 28 '22 22:11

MattDAVM


1 Answers

You should use maxDate option instead of disabledDates.

Here a working example:

$('#data_move').datetimepicker({
  locale: 'pt-br',
  maxDate: moment()
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/pt-br.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>

<div class='input-group date' id='data_move'>
  <input type='text' class="form-control" />
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>
like image 161
VincenzoC Avatar answered Dec 09 '22 21:12

VincenzoC