Jquery UI datepicker. Disable array of Dates

后端 未结 7 802
野的像风
野的像风 2020-11-22 02:21

I have been trying to search for a solution to my Jquery ui datepicker problem and I\'m having no luck. Here\'s what I\'m trying to do...

I have an application where

7条回答
  •  不要未来只要你来
    2020-11-22 02:44

    beforeShowDate didn't work for me, so I went ahead and developed my own solution:

    $('#embeded_calendar').datepicker({
                   minDate: date,
                    localToday:datePlusOne,
                   changeDate: true,
                   changeMonth: true,
                   changeYear: true,
                   yearRange: "-120:+1",
                   onSelect: function(selectedDateFormatted){
    
                         var selectedDate = $("#embeded_calendar").datepicker('getDate');
    
                        deactivateDates(selectedDate);
                       }
    
               });
    
    
                  var excludedDates = [ "10-20-2017","10-21-2016", "11-21-2016"];
    
                  deactivateDates(new Date());
    
                function deactivateDates(selectedDate){
                    setTimeout(function(){ 
                          var thisMonthExcludedDates = thisMonthDates(selectedDate);
                          thisMonthExcludedDates = getDaysfromDate(thisMonthExcludedDates);
                           var excludedTDs = page.find('td[data-handler="selectDay"]').filter(function(){
                               return $.inArray( $(this).text(), thisMonthExcludedDates) >= 0
                           });
    
                           excludedTDs.unbind('click').addClass('ui-datepicker-unselectable');
                       }, 10);
                }
    
                function thisMonthDates(date){
                  return $.grep( excludedDates, function( n){
                    var dateParts = n.split("-");
                    return dateParts[0] == date.getMonth() + 1  && dateParts[2] == date.getYear() + 1900;
                });
                }
    
                function getDaysfromDate(datesArray){
                      return  $.map( datesArray, function( n){
                        return n.split("-")[1]; 
                    });
                 }
    

提交回复
热议问题