I am trying to trigger a change when specific dates are clicked in datepicker. I can't figure out why it isn't working. In this example, when I click on the first array date (Feb 7), nothing happens. When I click on the second (Feb 21), I get the correct alert completed. When I click anywhere else, I get both the completed and open alerts.
jQuery(document).ready(function($){
var pastorder = ["2/7/2018", "2/21/2018"];
function eventDays(date) {
var string = ( date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
if (jQuery.inArray(string, pastorder) != -1){
return [true, "pastorder"];
} else {
return [true, "open" ];
}
}
jQuery('.week-picker').datepicker({
onSelect: function (dateStr) {
var date = new Date(dateStr);
var string = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
if ($.inArray( string, pastorder )) { // In Pastorder array
alert( "completed" );
}
if ($.inArray( string, pastorder ) == -1) { // Not in array
alert( "open" );
}
},
beforeShowDay: eventDays
});
});
Here is my first codepen.
I also tried targeting the css without luck.
onSelect: function (dateStr) {
var date = new Date(dateStr);
var string = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
if ($(this).hasClass( "pastorder")) {
alert( "completed" );
}
if ($(this).hasClass( "open")) {
alert( "open" );
}
},
Here is my second codepen.