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 display the selected date to the console. The tutorial only shows one date at a time. I'd like to display all the dates that are selected when a date is picked. So technically an array of selected dates. Is there a way to do this? Here's a jsFiddle
HTML
<div class="date-pick"></div>
JS
$(function() {
$('.date-pick')
.datePicker({
createButton: false,
displayClose: true,
closeOnSelect: false,
selectMultiple: true,
inline: true,
})
.bind(
'click',
function() {
$(this).dpDisplay();
this.blur();
return false;
}
)
.bind(
'dateSelected',
function(e, selectedDate, $td, state) {
console.log('You ' + (state ? '' : 'un') // wrap
+ 'selected ' + selectedDate);
}
)
.bind(
'dpClosed',
function(e, selectedDates) {
console.log('You closed the date picker and the ' // wrap
+ 'currently selected dates are:');
console.log(selectedDates);
}
);
});
Upvotes: 0
Views: 1374
Reputation: 106
From the documentation:
dpGetSelected( ) returns Array
Gets a list of Dates currently selected by this datePicker. This will be an empty array if no dates are currently selected or NULL if there is no datePicker associated with the matched element.Example:
Will alert an empty array (as nothing is selected yet)$('.date-picker').datePicker(); alert($('.date-picker').dpGetSelected());
Upvotes: 2