Disabling Prior Dates But Leaving Field Blank?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 15:15:44

问题


I am setting minDate: 'now'; in order to prevent picking dates prior to the current date. However, this populates the field with the current date. Not necessarily a big deal, however, if I am performing validation on the field (i.e., that it is populated), then the user can still submit even though not having picked a date.

Any way around this?

EDIT: Sorry, but it appears that using daysOfWeekDisabled shows the current date. Still not sure what to do.


回答1:


Your problem is similar to the one described here: issue #1289.

To solve it just set useCurrent to false. Here a working example:

$("#datetimepicker1").datetimepicker({
  minDate: moment(),  // min date = now
  useCurrent : false, // do not use current date by default
  daysOfWeekDisabled: [5] // disable some weekdays (e.g. fridays)
})
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.42/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.15.2/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.42/js/bootstrap-datetimepicker.min.js"></script>

<div class="input-group date" id="datetimepicker1">
  <input type="text" class="form-control" />
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>



回答2:


What about this hack ? It doesn't allow selecting the previous day but it's still shown as enabled. Not sure if this will help.

("#mydp").datetimepicker({ minDate:(new Date()).setDate(new Date().getDate() - 1),
  useCurrent : false 
})


来源:https://stackoverflow.com/questions/40270771/disabling-prior-dates-but-leaving-field-blank

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