0
votes

jQuery UI Datepicker:

Hi,

I'm trying to have the pop-up calendar allow only the Monday dates in the future to be selected. I've tried this code:

$(function() {
    $('#dateWeekly').datepicker({
        showOn: 'both', // use to enable calendar button and focus 
        buttonImage: 'childtime/images/calendar.gif',
        buttonImageOnly: true,
        buttonText: 'Show Calendar',
        numberOfMonths: 3,
        showButtonPanel: true,
        minDate: -0, maxDate: '+12M',
        // beforeShowDay: function(date){ return [date.getDay() == 1,""]}
        beforeShowDay: function(date) { return [date.getDay() == 1, "" && date.getTime() != today.getTime(), ""]; }
    });
});

This disables all past dates, and disables all future days except Mondays (so far so good), but it fails to disable today's date if today is Monday. Any suggestions will be appreciated. Thanks!

3
by default it shows today's date. You dont need to configure it to show current date - Starx

3 Answers

0
votes

Set minDate to +1d.

As you are supposed to pick only future mondays, today shouldn't be able to be picked, no matter what day it is.

And you can simplify your beforeShowDay to:

beforeShowDay: function(date) {
        return [date.getDay() == 1, ""];
}
0
votes

Below Code might be the solution for this question.

    beforeShowDay: function(date) { 
          returnFlag = true;    
              currentDate = new Date();
          if( date.getDay() == 1 && date.getDate() == currentDate.getDate()  
                                 && date.getMonth() == currentDate.getMonth()){
                returnFlag = false;
          }
          return [returnFlag,'',false];

    }
-1
votes

Maybe that could help

$(function() {
  $('#dateWeekly').datepicker({
    showOn: 'both', // use to enable calendar button and focus 
    buttonImage: 'childtime/images/calendar.gif',
    buttonImageOnly: true,
    buttonText: 'Show Calendar',
    numberOfMonths: 3,
    showButtonPanel: true,
    minDate: -0, maxDate: '+12M',
    beforeShowDay: function(date) { 
      // from here
      var selectable = true;
      var today = new Date()
      if( today.getDay() == 1 && date.getDate() == today.getDate() )selectable = false;
      return [selectable,'',false];
      // til here
    }
  });
});