0

I am new to Angularjs. I wonder is there any filtering mechanism for the Angular Material Date Picker(md-datepicker), So that I can choose only Monday when other days of the week is choosen, provided all the days are enabled. For example, when i clicked on 14-04-2016(Thursday), (11-04-2016)monday of that week should be automatically selected.

Let me know if any other details needed. Any help much appreciated. Thanks in advance.

1 Answer 1

1

You can write a filter for your datepicker:

 <md-datepicker ng-model="myDate" md-date-filter="onlyMondays"></md-datepicker>

 $scope.onlyMondays = function(date) {
    var day = date.getDay();
    return day === 1;
 }

Or if you want to let all days selectable you could change the date to monday in the background with:

<md-datepicker ng-model="selectedDate"></md-datepicker>

you could set the date to the last monday afterwards:

var daysToSubstract = $scope.selectedDate.getDay() - 1; 
$scope.myDate.setDate($scope.selectedDate.getDate() - daysToSubstract);
2
  • Thank you @kabaehr for your contribution to my issue. I have added the above code as per my requirement. $scope.onlyMondayToSelectStartDate = function (date) { var daysToSubstract = 6; if ($scope.filtersDat.selectedStartdate.Datecontent[0].getDay() != 0) daysToSubstract = $scope.filtersDat.selectedStartdate.Datecontent[0].getDay() -1; $scope.filtersDat.selectedStartdate.Datecontent[0].setDate($scope.filtersDat.selectedStartdate.Datecontent[0].getDate() -daysToSubstract); return false; }
    – MGT_711792
    Apr 19, 2016 at 11:06
  • How could you then select an entire week regardless of the date chosen. Even though you select Tuesday, Monday until Sunday is the output. May 6, 2016 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.