kineticsocial / angularjs-datetime-picker

AngularJS DateTime Picker Without JQuery and Bootstrap
MIT License
66 stars 79 forks source link

How to restrict past 30 days ? #52

Open KoushikVanama opened 6 years ago

KoushikVanama commented 6 years ago

I have added a class "selectable" to disable visibility of particular date item like this.

ng-class="{',
        '        selectable: getVisibility(today, mv, day),',
        '        selected: (day == selectedDay),',
        '        today: (today == (mv.year + \'-\' + (mv.month + 1) + \'-\' + day)),',
        '        weekend: (mv.leadingDays.length + day)%7 == 1 || (mv.leadingDays.length + day)%7 == 0',
        '      }"

and the function like this

scope.getVisibility = function(d, mv, day) {
                if(scope.cusVal){
                    var temp = new Date(d);var futureDates = new Date(d);
                    temp.setDate(temp.getDate()-window.cusVal);
                    futureDates.setDate(futureDates.getDate());
                    return (temp <= new Date(mv.year + '-' + (mv.month + 1) + '-' + day) ? true : false) && (futureDates >= new Date(mv.year + '-' + (mv.month + 1) + '-' + day) ? true : false);
                }else if(!scope.cusVal){
                    return (new Date(d) >= new Date(mv.year + '-' + (mv.month + 1) + '-' + day) ? true : false);
                } else {
                    return (new Date(d) <= new Date(mv.year + '-' + (mv.month + 1) + '-' + day) ? true : false);
                }
            }

Currenlty, I am disabling either past dates or future dates but not specific date range. How can I make visible only the past 30 days?