2

I was wondering how it would be possible to disable the next monday, when the day now is a friday. I can disable every monday, but I only want to disable one, when the day is friday and only the first monday, not every monday.

I was using this, I am getting in the if loop, but it's not returning anything.

minDate: new Date(y,m,fridayNotMonday),

function fridayNotMonday() 
{
  var vdate = new Date();
  var vday = vdate.getDay();
  var vm = vdate.getMonth(), vd = vdate.getDate(), vy = vdate.getFullYear();
  var vd1 = vdate.getDate() + 2;
  var vd2 = vdate.getDate() + 4;

  if (vday == 5) {
    alert("friday");
    firstDate: new Date(vy,vm,vd2);
    return firstDate
  } else {
    firstDate1: new Date(vy,vm,vd1);
    return firstDate1;
  }
}
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
  • [This](http://davidwalsh.name/jquery-datepicker-disable-days) might help – keyser Oct 09 '12 at 09:00
  • [This](http://stackoverflow.com/questions/677976/jquery-ui-datepicker-disable-specific-days) might help you solve your problem. It looks like a duplicate of your issue but with multiple dates, so it should provide some guidance in solving your problem – Bird87 ZA Oct 09 '12 at 09:11

1 Answers1

0

You should use the beforeShowDay option of the datepicker

var now = new Date();
var day = now.getDay();
// on the following line 5 means friday. Days start counting from 0=sunday to 6=saturday.
// so if now is friday then find the date of the following monday
var disabled = (day===5)? new Date(now.getFullYear(), now.getMonth(), now.getDate()+3): null;

$('#datepickerelement').datepicker({
    beforeShowDay:function(current){
        // if the disabled date we calculate is the same as the one the plugin tries to show
        // then set its selectable status to false..
        if (disabled !== null && disabled.getTime() === current.getTime() ) {
            return [false];
        } else {
            return [true];
        }

    }
});

Demo at http://jsfiddle.net/r6QUd/2/

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317