Let's say I want 5/2/2011 (or any other day) to be a different color than the rest of the days. Is this possible?
This is an example item for a particular day
<td class=" " onclick="DP_jQuery_1305738227207.datepicker._selectDay('#datepicker',4,2011, this);return false;"><a class="ui-state-default ui-state-hover" href="#">11</a></td>
I don't know if there's any way to override how the datepicker creates ids/classes for each day.
Working Example: http://jsfiddle.net/hunter/UBPg5/
You can do this by adding a beforeShowDay
callback
Bind your callback:
$("input:text.date").datepicker({
beforeShowDay: SetDayStyle
});
Create your function with some static array of bad dates or construct this array somewhere else:
var badDates = new Array("5/2/2011");
function SetDayStyle(date) {
var enabled = true;
var cssClass = "";
var day = date.getDate();
var month = date.getMonth() + 1; //0 - 11
var year = date.getFullYear();
var compare = month + "/" + day + "/" + year;
var toolTip = badDates.indexOf(compare) + " " + compare
if (badDates.indexOf(compare) >= 0) cssClass = "bad";
return new Array(enabled, cssClass, toolTip);
}
Create your styles
.bad { background: red; }
.bad a.ui-state-active { background: red; color: white; }
http://jqueryui.com/demos/datepicker/#event-beforeShowDay
The function takes a date as a parameter and must return an array with [0] equal to true/false indicating whether or not this date is selectable, [1] equal to a CSS class name(s) or '' for the default presentation, and [2] an optional popup tooltip for this date. It is called for each day in the datepicker before it is displayed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With