I am initializing jquery ui's datepicker as follows:
var datesArray=['3/7/2016','3/12/2016']
$('#datepicker').datepicker({
inline: true,
beforeShowDay: function (date) {
var theday = (date.getMonth()+1) +'/'+
date.getDate()+ '/' +
date.getFullYear();
return [true,$.inArray(theday, datesArray) >=0 ? "specialDate":''];
}
});
This creates the calendar with the class specialDate applied to all dates in datesArray.
Additionally, I need to add a unique data attribute value (something like data-value="39") to these same dates on initialization of the datepicker, but I am not sure how to select the dates.
I can use something like
var datavalues = {
"3/7/2016" : "38",
"3/12/2016" : "39"
};
where 38 and 39 are the data-values.
This question about adding a custom parameter gets me close, but I'm not sure exactly how to use this to just add the data attributes on creation.
onChangeMonthYear, but it would still be pretty cumbersome and/or fragile. What're you trying to achieve? I'm fairly sure there're better ways than constantly binding and unbinding dataonSelectto pick the one you need, when you need it. Or not bother binding it at all, just keep it as an in-memory variable