I need to disable all dates which are not from the currently focused month.
Tried using date-disabled
attribute based on selected date, but it forever disables dates. The dates remain disabled when month is changed.
I thought of an alternative solution : All dates not from currently focused month have a class "text-muted" applied to them. Tried to create the below directive which checked the class and disabled dates. But this is not working at all. Can anyone take a look?
HTML:
<datepicker ng-model="dt" show-weeks="false" disable-muted-dates />
Javascript:
angular.module('app', ['ui.bootstrap'])
.directive('disableMutedDates',[function () {
return {
link:function (scope,element) {
var datepicker = element;
var table = angular.element(datepicker.children()[0]);
var tbody = angular.element(table.children()[1]);
var trs = angular.element(tbody.children());
for (var i = trs.length - 1; i >= 0; i--) {
var tr = angular.element(trs[i]);
var tds = angular.element(tr.children());
for (var j = tds.length - 1; j >= 0; j--) {
var td = angular.element(tds[j]);
if (angular.element(td.children()[0]).prop('tagName') === 'BUTTON') {
var button = angular.element(td.children()[0]);
var span = angular.element(button.children()[0]);
if (span.hasClass('text-muted')) {
button.attr('disabled',true);
};
};
};
};
}
}
}])
PEN : http://codepen.io/cyrilpanicker/pen/qdpPjY?editors=101