I have the following code:
$(document).ready(function(){
$(".datepicker").each(function() {
$(this).datepicker({
beforeShowDay: function(date){ return [$(this).parent().find("span.days").html(), ""] },
});
});
});
With this body code…
<div>
<span class="days">(date.getDay() == 1 || date.getDay() == 4)</span>
<input type="text" class="datepicker">
</div>
<div>
<span class="days">(date.getDay() == 2 || date.getDay() == 5)</span>
<input type="text" class="datepicker">
</div>
What I want to be able to do is have each datepicker have different days pickable.
The way i’m trying to do this (putting the varying part of the beforeShowDay code in a span) may not be the most elegant so feel free to take my code apart and change it if necessary.
You could create an object keeping the pickable days, like this:
You can give it a try here. The
dp1anddp2are IDs of the controls..or any attribute you can map really, like this:The concept is pretty simple, take the ID to get the array of days for this picker, then use
$.inArray()to see if the day we’re on is in that array. If these day selections may be shared, don’t use an ID, instead do something likedata-pickerTypefor the attribute, and replacethis.idwith$(this).attr("data-pickerType")in the code above.Note: I left the
.each()intact because I know you need it for reasons outside the current question.