【问题标题】:Disable past dates in datepicker-popup在 datepicker-popup 中禁用过去的日期
【发布时间】:2016-04-14 02:57:20
【问题描述】:

我在下面的代码 sn-p 中有 datepicker 控件。

<input type="text" name="startDate" class="form-control  input-sm" datepicker-popup="dd-MMMM-yyyy" ng-model="startDate" required />

在这里,我必须在 datepicker 控件中禁用过去的日期,下面是我已配置但无法正常工作的内容。我在这里遗漏了什么吗?

App.config(['datepickerConfig', 'datepickerPopupConfig', function (datepickerConfig, datepickerPopupConfig) {
    datepickerConfig.startingDay = 1;
    datepickerConfig.showWeeks = true;

    datepickerPopupConfig.datepickerPopup = "dd-MMMM-yyyy";
    datepickerPopupConfig.currentText = "Now";
    datepickerPopupConfig.clearText = "Erase";
    datepickerPopupConfig.closeText = "Close";
}]);

【问题讨论】:

标签: angularjs datepicker angular-ui-bootstrap


【解决方案1】:

如果您想缩小可能的日期范围,请添加 min-datemax-date just as in the example

这是相关的part of documentation

  • max-date (默认: null) - 定义最大可用日期。
  • min-date(默认值:null)- 定义最短可用日期。

【讨论】:

    【解决方案2】:

    从 Angular ui-bootstrap 版本 1.1.0 开始,您需要使用名为 datepicker-options 的属性来配置日期选择器:

    <input type="text" class="form-control" datepicker-options="dateOptions" datepicker-popup="dd-MMMM-yyyy" is-open="popup.opened"/>
    <span class="input-group-btn">
        <button type="button" class="btn btn-default" ng-click="open()">
            <i class="glyphicon glyphicon-calendar"></i>
        </button>
    </span>
    

    现在您只需将 minDate 属性设置为当前日期或您喜欢的任何其他日期作为日期选择器的最小日期。与其在应用程序的 .config 块中编写日期选择器配置,不如将其编写在控制器或服务中:

    $scope.dateOptions = {
       minDate: new Date() 
    };
    
    $scope.popup = {
       opened: false
    };
    
    $scope.open = function() {
       $scope.popup.opened = true;
    };
    

    更多信息,请阅读official documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-12
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多