【问题标题】:How to prevent entry of a disabled date in bootstrap-datepicker如何防止在 bootstrap-datepicker 中输入禁用日期
【发布时间】:2017-03-30 15:29:03
【问题描述】:

我正在运行 uxsolutions / bootstrap-datepicker (https://github.com/uxsolutions/bootstrap-datepicker)。

我已经在弹出日历小部件中禁用了日期,很好(参见下面的代码)。然而,在日期的文本框中,我可以输入禁用的日期(下面的屏幕截图)。

如何让日期框识别禁用的日期并阻止它们被输入?

  $('#eventDate-container .input-group.date').datepicker({
    weekStart: 1, // calendar starts on Monday
    autoclose: true,
    todayHighlight: true,
    startDate: "4/10/2017", // disables all dates prior to this date
    datesDisabled: ['01/01/1970', '12/31/2099'] // placeholder sample for possible future use
  });

【问题讨论】:

    标签: bootstrap-datepicker


    【解决方案1】:

    我知道这不是您使用的插件 (Bootstrap 3 Date/Time Picker) 但这可能会有所帮助... 我今天一直在做同样的事情,我从您正在使用的确切插件开始,但后来去了Bootstrap 3 Date/Time Picker,因为它有更多选项

    Disable manual entry of date in , force selection via picker. #212

    【讨论】:

    • 酷,谢谢@McKabue。稍后我会查看该插件,但目前,我的 uxsolutions/bootstrap-datepicker 大量使用,在我的 Web 应用程序中大量使用,因此此刻切换将是巨大的,我只需要解决我的眼前问题。
    • 您可以尝试强制用户直接使用选择器并禁用输入
    • 好的,谢谢@McKabue,这不是一个很好也不理想的选择……但你是对的,尽管如此,这是一个选择。
    • +尝试将 readonly="readonly" 添加到输入或 disabled="disabled" [可能会导致一些副作用]
    • 不(抱歉)@McKabue 但您正在规避问题并绕过 OQ。 (1) 我需要允许用户在文本框中输入日期。 (2) 我需要该文本框遵循 bootstrap-datepicker 中的日期禁用规则。 (3) 我需要继续使用 uxsolutions/bootstrap-datepicker 插件。那么这可以实现还是这个插件太弱而无法提供?
    【解决方案2】:

    我修补了代码:

    keydown: function(e){
        case 13: // enter
            if (!this.o.forceParse)
                break;
            **if (this.picker.find('td.focused.day').hasClass('disabled'))
                break;**
            focusDate = this.focusDate || this.dates.get(-1) || this.viewDate;
            if (this.o.keyboardNavigation) {
                this._toggle_multidate(focusDate);
                dateChanged = true;
            }
    

    【讨论】:

      猜你喜欢
      • 2022-12-15
      • 2014-06-12
      • 1970-01-01
      • 2014-09-23
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      相关资源
      最近更新 更多