Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  124] [ 5]  / answers: 1 / hits: 5385  / 11 Years ago, thu, january 9, 2014, 12:00:00

I have one array for disabled dates and another for dates to be highlighted. Is there a way to code this?



e.g.:



beforeShowDay: function(date){
var unavilble = jQuery.datepicker.formatDate('yy/mm/dd', date);
var newstring = [ arrayable.indexOf(unavilble) == -1 ];
return newstring;
},


2nd array:



var datet = ['2014/01/19', '2014/01/20'];
//tips are optional but good to have
var tips = ['some description','some other description'];

function highlightDays(date) {
for (var i = 0; i < datet.length; i++) {
if (new Date(datet[i]).toString() == date.toString()) {
return [true, 'highlight', tips[i]];
}
}
return [true, ''];
}
beforeShowDay: highlightDays,

More From » jquery

 Answers
9

Try something like



var datet = ['2014/01/19', '2014/01/20'];
//tips are optional but good to have
var tips = ['some description', 'some other description'];
var arrayable = ['2014/01/01', '2014/01/08', '2014/01/15', '2014/01/22', '2014/01/29']
$('input').datepicker({
dateFormat: 'yy/mm/dd',
beforeShowDay: function (date) {
var datestring = jQuery.datepicker.formatDate('yy/mm/dd', date);
var hindex = $.inArray(datestring, datet);
if (hindex > -1) {
return [true, 'highlight', tips[hindex]];
}
var aindex = $.inArray(datestring, arrayable);
return [aindex == -1]
}
})


Demo: Fiddle


[#48863] Wednesday, January 8, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lewis

Total Points: 739
Total Questions: 100
Total Answers: 94

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
lewis questions
Tue, May 11, 21, 00:00, 3 Years ago
Fri, Jul 10, 20, 00:00, 4 Years ago
Wed, May 27, 20, 00:00, 4 Years ago
Thu, Apr 23, 20, 00:00, 4 Years ago
;