Dotcomtunisia
Dotcomtunisia

Reputation: 123

beforeShowDay don't disabled day in current month

i have this script:

var unavailableDates=["2014-09-22","2014-09-31","2014-10-17","2014-10-20"] ;
    function unavailable(date) {
  dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
   alert(dmy);
  if ($.inArray(dmy, a) < 0) {
    return [true,"enabled","Book Now"];
  } else {
    return [false,"disabled","Booked Out"];
  }

}
$('#datedepart').datepicker({

       dateFormat: "dd/mm/yy",
       beforeShowDay: unavailable,
minDate:3});

my problem days "2014-10-17" and "2014-10-20" disabled but not "2014-09-22" and "2014-09-31"

Upvotes: 1

Views: 177

Answers (2)

Ritesh
Ritesh

Reputation: 4956

date.getMonth() returns months smaller than 10 as single numeric value e.g 9 for september but 10 for october. You need to add an extra 0 as a string or remove 0's from your unavailableDates in month values like :

var unavailableDates=["2014-9-22","2014-9-31","2014-10-17","2014-10-20"] ;

Another issue is, you are searching in a while your array name is "unavailableDates".

Upvotes: 1

Nicolas Albert
Nicolas Albert

Reputation: 2596

This is not what you want ?

dmy = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate();

And

$.inArray(dmy, unavailableDates)

Upvotes: 0

Related Questions