I am using jQuery UI datepicker so the user can select a date. I need to paint 7 days after the selected date.
For example, if the user has selected 1.1.2015, days 2.1.2015before 8.1.2015should be colored by clicking (on 1.1.2015). I have been following this , but I cannot do this work.
Basically, what I'm doing is creating an array of future dates (based on calculating milliseconds from the selected date + 86,400,000 milliseconds for each day), and then trying to apply the class cssto this array. Please inform.
EDIT:
Maybe I should have mentioned, but this collector is built-in, so changes should happen instantly.
EDIT2:
Here is an example using jsfiddle .
JS:
var arrayOfFollowingWeekDates = [];
var selectedStartingDate;
$('#datepicker').datepicker({
onSelect: function(dateText, inst){
selectedStartingDate = dateText;
var selectedDateAsObject = $(this).datepicker('getDate');
arrayOfFollowingWeekDates = calcFollowingtWeekDates(selectedDateAsObject);
if(selectedDateAsObject > new Date){
console.log(selectedStartingDate);
}else{
console.log("bad date.");
}
},
inline: true,
showOtherMonths: true,
beforeShowDay: function(day, date){
var day = day.getDay();
if (day == 5 || day == 6){
return [false, ""];
} else {
return [true, ""];
}
var highlight = arrayOfFollowingWeekDates[date];
if (highlight) {
return [true, "event", highlight];
} else {
return [true, '', ''];
}
}
});
function calcFollowingtWeekDates(selectedDateObj){
var followingWeek = [];
var tempArrayOfNextDates = [];
var selectedDateInMilliseconds = selectedDateObj.getTime();
console.log("selected date in milliseconds: "+selectedDateInMilliseconds);
tempArrayOfNextDates[0]=selectedDateInMilliseconds;
var day;
var prevDay=selectedDateInMilliseconds;
for(var i=0;i<7;i++){
tempArrayOfNextDates[i] = 86400000 + prevDay;
day = new Date(tempArrayOfNextDates[i]);
prevDay = tempArrayOfNextDates[i];
followingWeek[i]=day;
console.log("next day is : "+ day);
}
return followingWeek;
}
CSS
.event a {
background-color: #42B373 !important;
background-image :none !important;
color: #ffffff !important;
}
source
share