仅显示datepicker中的当前月份,并且应使用angularjs禁用剩余的所有月份

时间:2022-06-24 18:06:24

I have datepicker showing only months. It should show only current month and remaining months should be disabled.

我有datepicker只显示几个月。它应仅显示当前月份,应禁用剩余月份。

I have tried with min-date and max-date, but it is not working.

我尝试过min-date和max-date,但它没有用。

HTML:

HTML:

<input type="text" class="form-control" 
  readonly="readonly" ng-model="xxxx"
  min-mode="'month'" min-date="startmnth" max-date="endmnth"
  datepicker-popup="yyyy-MM" is_open="status.date_opened" 
  ng-required="true" placeholder="YYYY-MM" 
  datepicker-options="datepickerOptions" 
  datepicker-mode="'month'" ng-click="openfromDate($event)" 
  show-button-bar="false">

JS:

JS:

$scope.startmnth = new Date().getMonth()
$scope.endmnth = new Date().getMonth()

$scope.datepickerOptions = {
    startingDay: 1,
};

$scope.openfromDate = function ($event) {                    
    $event.preventDefault();
    $event.stopPropagation();        
    $scope.status.date_opened = true;
 };

1 个解决方案

#1


0  

You can add "dateDisabled: this.disabledDates" as part of your options, and then create a function like this:

您可以添加“dateDisabled:this.disabledDates”作为选项的一部分,然后创建如下函数:

this.disabledDates = function(data) {
    var date = moment(data.date);
    //check date and return true/false to disable/enable
    return false;//to disable
}

#1


0  

You can add "dateDisabled: this.disabledDates" as part of your options, and then create a function like this:

您可以添加“dateDisabled:this.disabledDates”作为选项的一部分,然后创建如下函数:

this.disabledDates = function(data) {
    var date = moment(data.date);
    //check date and return true/false to disable/enable
    return false;//to disable
}