views:

490

answers:

1

Hi, what I am trying to do is grey out some days of the week for a venue for when it is closed. Each venue might be closed on different days.

I can use the following code as a test to close out all Sundays:

$('#bookingDatepicker').datepicker({
                minDate: 0, 
                maxDate: '+3M',
                dateFormat: 'DD, d MM, yy',
                altField: '#actualDate',
                altFormat: 'yy-mm-dd',
                beforeShowDay:  closedDays
            });

function closedDays(date) {
  if (date.getDay() == 0){ 
  return [false,"","Venue Closed"]; 
  } else { return [true, ""];
}
}

However I might have to close out more than one day and they might not run next to each other. In my code from the database I can create a string, examples below, which show what days are open...

1,2,3,4,5,6,0    //I would want to show no days closed
2,3,4,5,6        //I would want to show Sunday (0) and Monday (1) closed

I am not sure what to do with this though to get the code above to work. I am using PHP to create the string so can manipulate it using that if need be.

EDIT

As is usual when you post a question you get a minor breakthrough! I have developed the code below, it works if I use the dummy data in it, however I need find a way of wrapping my string values in "". That is now causing me trouble, if I just use var cloDays = [2,3,4,5] it ceases to work

var cloDays = ["2","3","4","5"]; 
 function closedDays(date){
 var sDate = date.getDay().toString();
 if ($.inArray(sDate, cloDays) == -1) return [false,"","Venue Closed"];
 else return [true, ""];
}
A: 

Managed to fix it by running my string through the code below, basically explodes it into a PHP array and then encodes it using JSON_Encode. Seems to work perfectly:

$cloDays = json_encode(explode(",", $cloDays));  
bateman_ap