views:

52

answers:

2

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!

A: 

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
    }
  });
});
markcial
Simen Echholt
date.getDay() outputs day of the week, and 1 is monday, so maybe you had not read completely the code i wrote.
markcial
Ok, after looking at it again I see the logic, but it's still wrong. Your logic is that if today is a monday and the date we are checking is today, disable it. But that's not what your code does. `today.getDay() == 1` is correct, but the other condition is wrong. You're just comparing the day of the month, but not what month or year it is. So if today is the 12th of July 2010 (a monday), it will disable the 12th of August, 12th of Sept etc because these are on the same_day_ as today. In addition, you are not enabling only mondays to be picked (aka `date.getDay() == 1`)
Simen Echholt
A: 

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, ""];
}
Simen Echholt