angularjsui.bootstrap

Disable future days at ui.bootstrap.datepicker Angularjs


I am using the datepicker of UI Bootstrap: (there is a Plunker there that disable the past dayswith a button).

Can anyone please help me to disable the future days without any button?

I tried change the function of the button like that, but it didn't worked:

$scope.toggleMin = function() { $scope.options.minDate = $scope.options.minDate ? **new Date()** : **null** ; };

And this is a button, I'd like to disable without a button.


Solution

  • Just set maxDate in options to the date you want to restrict to.

    $scope.options = {
      customClass: getDayClass,
      maxDate: new Date(), // restrict maximum date to today
      showWeeks: true
    };
    

    Otherwise, if you need to change it after the options are set you can just do:

    $scope.options.maxDate = new Date(), // restrict maximum date to today
    

    Here's the updated Plunker with days after today disabled: https://plnkr.co/edit/0iqNNEcATzv4t8h8n41X?p=preview