kfm
kfm

Reputation: 143

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.

Upvotes: 2

Views: 7739

Answers (2)

rvchauhan
rvchauhan

Reputation: 89

Set your datepicker class and Set endDate = new Date()

    $('.date-datepicker').datepicker({
        autoclose: true,
        endDate: new Date()
    });

Upvotes: 0

K Scandrett
K Scandrett

Reputation: 16540

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

Upvotes: 4

Related Questions