angular angular - 6 months ago 110
AngularJS Question

disable all previous dates in angular bootstrap datetimepicker

I am creating a project using angularjs. I am integrated the angulardatetimepicker from the link:

https://github.com/dalelotts/angular-bootstrap-datetimepicker.

Now I want to disable all previous dates from current date.
Here is my code:

function beforeRender($view, $dates, $leftDate, $upDate, $rightDate) {
var minDate = moment().startOf($view).valueOf();
for(var i=1; i < $dates.length;i++) {
if(new Date().getTime() > $dates[i].utcDateValue) {
$dates[i].selectable = false;
}
}
}


This code not disabled dates correctly

Answer

Minor Changes in your loop:

   function beforeRender($view, $dates, $leftDate, $upDate, $rightDate) {
    var minDate = moment().startOf($view).valueOf();  
    for(var i=0; i < $dates.length;i++) {
       if(minDate > $dates[i].utcDateValue) {
          $dates[i].selectable = false;
       }
    }     
    }