【问题标题】:Bootstrap datetimepicker widget how to allow invalid mysql dates like '0000-00-00'?Bootstrap datetimepicker小部件如何允许无效的mysql日期,如'0000-00-00'?
【发布时间】:2019-05-09 01:07:29
【问题描述】:

我的 Php-Mysql 应用程序需要允许并在 UI 中设置一些无效日期,例如 mysql 默认日期 0000-00-00。

当我尝试在引导程序 DateTime 小部件中执行此操作时,它似乎确实删除了 0000-00-00 并变为空字段。我的代码如下

//do the dates now
$("#date").datetimepicker({
    format: "YYYY-MM-DD",
    icons: {
        time: "fa fa-clock-o",
        date: "fa fa-calendar",
        up: "fa fa-chevron-up",
        down: "fa fa-chevron-down",
        previous: "fa fa-chevron-left",
        next: "fa fa-chevron-right",
        today: "fa fa-screenshot",
        clear: "fa fa-trash",
        close: "fa fa-remove"
    }
});

如何添加/允许选项以允许用户输入无效日期,例如“0000-00-00”?

【问题讨论】:

    标签: bootstrap-4 datetimepicker bootstrap-datetimepicker


    【解决方案1】:

    实际上,如果您愿意,允许 0000-00-00 作为您的输入日期非常容易。 bootstrap datepicker 提供了一个选项 forceParse: false

    将此选项设置为 false 会为您带来所有魔力,默认情况下为 true 但请注意它的价格很高;) :)

    Type: Boolean
    Default: true
    
    Whether or not to force parsing of the input value when the picker is closed. That is, when an invalid date is left in the input field by the user, the picker will forcibly parse that value, and set the input’s value to the new, valid date, conforming to the given format.
    

    将此选项设置为 false 以允许您输入任何错误的日期

    来源:https://bootstrap-datepicker.readthedocs.io/en/stable/options.html#forceparse

    【讨论】:

      猜你喜欢
      • 2017-09-21
      • 2011-08-23
      • 1970-01-01
      • 2013-06-09
      • 2015-07-19
      • 2013-07-12
      • 2016-06-04
      • 2012-01-31
      • 2012-12-22
      相关资源
      最近更新 更多