Disable future dates in Bootstrap 3 Datetimepicker

旧城冷巷雨未停 提交于 2019-12-24 00:39:21

问题


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")
    ]
});

回答1:


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>


来源:https://stackoverflow.com/questions/42974011/disable-future-dates-in-bootstrap-3-datetimepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!