Hello,
How can I get the selected month from a kendoCalendar??
i have this code behind:
$(function() {
var listaZile=[];
var today = new Date();
//data source
var selectedDates = [today.getDate() ];
//Calendar with multiselection
initCalendar($("#calendar").kendoCalendar(), selectedDates.slice());
});
function initCalendar(calendar, selectedDates, onUpdate) {
var kendoCalendar = calendar.data('kendoCalendar');
kendoCalendar.bind('navigate', function() {
setTimeout(function() {
updateCalendar(calendar, selectedDates);
}, 0);
});
updateCalendar(calendar, selectedDates);
calendar.on('click', function(event) {
var cell = $(event.target).closest('td');
var isClickedOnDayCell = cell.length !== 0 && isDayCell(cell);
if (isClickedOnDayCell) {
var date = dateFromCell(cell).getDate();
var isDateAlreadySelected = selectedDates.some(function(selected) {
return selected === date;
});
if (isDateAlreadySelected) {
selectedDates.splice(selectedDates.indexOf(date), 1);
} else {
selectedDates.push(date);
listaZile.push(date); //this return days selected!!!
}
updateCell(cell, selectedDates);
if (onUpdate !== undefined) {
onUpdate();
}
}
});
}
function updateCalendar(calendar, selectedDates) {
calendar.find('td > a').parent().each(function(i, item) {
var cell = $(item);
if (isDayCell(cell)) {
updateCell(cell, selectedDates);
}
});
}
function updateCell(cell, selectedDates) {
var isCellSelected = selectedDates.some(function(selected) {
return selected === dateFromCell(cell).getTime();
});
if (isCellSelected) {
cell.addClass('selected');
} else {
cell.removeClass('selected');
}
}
function isDayCell(cell) {
return /^\d{1,2}$/.test(cell.find('a').text());
}
function dateFromCell(cell) {
return new Date(convertDataValue(cell.find('a').attr('data-value')));
}
//convert from 'YYYY/MM/DD', where MM = 0..11
function convertDataValue(date) {
var regex = /\/(\d+)\//;
var month = +date.match(regex)[1] + 1;
return date.replace(regex, '/' + month + '/');
}
P.S I attached a view of my calendar window. the get value from month selection is undefined.
Thank you.