I need to make datepicker events added depending on where they clicked. For example: I need to filter some data by day and I can filter the same data also per month.
But with my code, only the month event is working because it is triggered when I click sometime next month
$('#calendario').datepicker({
format: "yyyy-mm-dd",
language: "pt-BR",
startDate: '+0d'
}).on('changeDate', function(e) {
let data = e.format(0,"yyyy-mm-dd");
location.href = '/cursos?date=' + data;
})
.on('changeMonth',function(e) {
let obj_mes = e.date;
let mes = obj_mes.toString().split(' ');
let mes_ano = $(".datepicker-switch").html();
let ano = mes_ano.split(' ');
location.href = '/cursos?mes=' + mes[1] + "&ano=" + ano[1];
});