Reputation: 3282
I am using a jQuery datepicker plugin from KelvinLuck. This date picker is a multi-select date picker. In the tutorial it shows how you can add 1 selected date, but I want to add many selected dates like this:
.dpSetSelected(
'18/06/2011', '19/06/2011, '20/06/2011
)
Is this possible? Here's the jsFiddle.
Upvotes: 0
Views: 1125
Reputation: 2507
Call dpSetSelected()
multiple times, e.g: dpSetSelected('18/06/2011').dpSetSelected('19/06/2011')
In case of your for
loop, just replace your JS code with this:
var dates = new Array('18/06/2011', '19/06/2011');
$(function() {
$('.date-pick')
.datePicker({
createButton: false,
displayClose: false,
closeOnSelect: true,
selectMultiple: true,
inline: true,
startDate: '01/01/2005',
endDate: '31/12/2011'
}).bind(
'click',
function() {
$(this).dpDisplay();
this.blur();
return false;
}
)
.bind(
'dateSelected',
function(e, selectedDate, $td, state) {
console.log('You ' + (state ? '' : 'un') // wrap
+ 'selected ' + selectedDate);
}
);
for (var i = 0; i < dates.length; i++) {
$('.date-pick').dpSetSelected(
dates[i]
);
}
});
Upvotes: 2