Usman Iqbal
Usman Iqbal

Reputation: 2429

MultipleDatePicker - how can I set the current day selected ?

I am unable to find anything on custom setting day. By default it always select current day of current year. How can I set to something different day and year .

HTML

   <div>
    <multiple-date-picker></multiple-date-picker>
   </div>

I saw the whole file of datepicker. I just saw these lines related to today.

var checkNavigationButtons = function () {
                    var today = moment(),
                        previousMonth = moment(scope.month).subtract(1, 'month'),
                        nextMonth = moment(scope.month).add(1, 'month');
                    scope.disableBackButton = scope.disallowBackPastMonths && today.isAfter(previousMonth, 'month');
                    scope.disableNextButton = scope.disallowGoFuturMonths && today.isBefore(nextMonth, 'month');
                },

official documentation: Documentation on date picker

Upvotes: 0

Views: 216

Answers (2)

Usman Iqbal
Usman Iqbal

Reputation: 2429

Thankyou @shashank for giving the idea. I solved it some thing like this.

      link: function (scope) {
                 /* if yes then find the last element of the dates array  which 
                 * is the last selected date of the year
                * after that convert it into yyy-mm-dd format
                * and assign to variable
                */
               if(scope.lastdateOfSelectedyear[scope.lastdateOfSelectedyear.length - 1])
               {
                var lastDayOfYear = moment(scope.lastdateOfSelectedyear[scope.lastdateOfSelectedyear.length - 1].endValue).format('YYYY-MM-DD');
                var objectTocontainSplittedString = {};

                /* split the string and put it in seperate variable */
                objectTocontainSplittedString = lastDayOfYear.split('-');

                var month_of_date_selected = objectTocontainSplittedString[1];
                var year_of_date_selected = objectTocontainSplittedString[0];
                var day_of_date_selected = objectTocontainSplittedString[2];

                /* last date of the selected dates month */                
                scope.month = moment(year_of_date_selected+'- 
                                    '+month_of_date_selected+'-'+day_of_date_selected);
               }
}

where lastdateOfSelectedyear is the array which i am passing in directive call it contains all the dates a user selected.

Upvotes: 1

Shashank
Shashank

Reputation: 2060

As mentioned in the official documentation:

<multiple-date-picker ng-model="myArrayOfDates"></multiple-date-picker>

You can try by giving ng-model="selectedDate" and set the selectedDate as:

HTML Code:

<multiple-date-picker ng-model="selectedDate"></multiple-date-picker>

JS Code:

$scope.selectedDate = moment().date(15); /* OUTPUT: 2018-03-15 */
/* -- or -- */
$scope.selectedDate = moment().date(2).month(10); /* OUTPUT: 2018-10-02 */
/* -- or -- */
$scope.selectedDate = moment().date(27).year(2017); /* OUTPUT: 2017-03-27 */

Upvotes: 0

Related Questions