set multiple dates via setDates doesn't highlight the days
If setting multiple dates via setDates or setUTCDates the method fill doesn't highlight the days at all.
I've make some fix for me:
inserted in line 885 (for version 1.4.0)
$.each(this.dates, function(i, d){
if (d.getUTCFullYear() === prevMonth.getUTCFullYear()
&& d.getUTCMonth() === prevMonth.getUTCMonth()
&& d.getUTCDate() === prevMonth.getUTCDate())
clsName.push('active');
});
Best regards, dgo42
could you please provide a pull request?
This bug is also present when setting a single date via setDate. The provided pull request fixes the use of setDate, too. Any reason why it has not been merged yet?
The above fixed just solve the highlighted color only. However, after setDates, when trying to deselect the highlighted date and it get unchanged. Please refer to the link to jsfiddle!
@alvin0618 i have same issue did you find a solution ?
I am not sure if my workaround to fix above issue will work with you guys look like the problem is :
when using setDates time is added to dates , and when trying to unselect the selected dates the time will be different for them , for example :
var dateAdded = ['2015-07-15'];
var dates = [];
$.each(dateAdded, function(i, dateStr){
var d = new Date();
var dateArray = dateStr.split("-");
d.setFullYear(parseInt(dateArray[0]));
d.setMonth(parseInt(dateArray[1])-1);
d.setDate(parseInt(dateArray[2]));
dates.push(d);
});
$('#multiple-date-container').datepicker('setDates', dates);
let's say at the time of setDates date will be :
Wed Jul 15 2015 13:19:26 GMT+0300
and at the time of unselect the date will be :
Wed Jul 15 2015 3:00:00 GMT+0300
i am not sure why time is different when doing setDates however i managed to do workaround by removing time from date while doing contains in function _toggle_multidate
instead of
var ix = this.dates.contains(date);
do the below:
var datesOnly = new DateArray();
$.each(this.dates, function(i, dateItem){
var dateOnly = new Date(dateItem.getFullYear(), dateItem.getMonth(), dateItem.getDate());
datesOnly.push(dateOnly);
});
var ix = datesOnly.contains(new Date(date.getFullYear(), date.getMonth(), date.getDate()));
Sorry for the late reply. Yes, I solved the problem by modifying the existing js
var DateArray = (function(){
var extras = {
get: function(i){
return this.slice(i)[0];
},
contains: function(d){
// Array.indexOf is not cross-browser;
// $.inArray doesn't work with Dates
/*
for (var i=0, l=this.length; i < l; i++)
if (this[i].valueOf() === val)
return i;
return -1;
*/
//20150604 alvin START - compare dates by yyyy mm dd, cut off time
var val = d && d.valueOf();
var dd = d.getDate();
var mm = d.getMonth();
var yyyy = d.getFullYear();
for (var i=0, l=this.length; i < l; i++) {
if( dd === this[i].getDate() &&
mm === this[i].getMonth() &&
yyyy === this[i].getFullYear() ){
return i;
}
}
return -1;
//20150604 alvin END - compare dates by yyyy mm dd, cut off time
},
remove: function(i){
this.splice(i,1);
},
replace: function(new_array){
if (!new_array)
return;
if (!$.isArray(new_array))
new_array = [new_array];
this.clear();
this.push.apply(this, new_array);
},
clear: function(){
this.length = 0;
},
copy: function(){
var a = new DateArray();
a.replace(this);
return a;
}
};
return function(){
var a = [];
a.push.apply(a, arguments);
$.extend(a, extras);
return a;
};
})();