禁用以前的日期,但将字段留空? [英] Disabling Prior Dates But Leaving Field Blank?

查看:87
本文介绍了禁用以前的日期,但将字段留空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置minDate: 'now';,以防止在当前日期之前选择日期.但是,这将使用当前日期填充该字段.但是,如果我要在现场执行验证(即已填充),则不一定有什么大事,即使用户没有选择日期,用户仍然可以提交.

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.

有什么办法解决吗?

对不起,但是看来使用daysOfWeekDisabled显示当前日期.仍然不确定该怎么办.

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

推荐答案

您的问题类似于此处描述的问题:问题#1289 .

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

要解决此问题,只需将 useCurrent 设置为false.这是一个工作示例:

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>

这篇关于禁用以前的日期,但将字段留空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆