I have this function that will set the datepicker for a given item id, and I'm trying to add a click function to the prev and next buttons. But nothing works. I searched the Internet to add clicks to these buttons, but they all give an identifier.
What am I doing wrong here?
function setDatepicker(element,curdate,identifier){
var minDateMaxDate = getCalendarsYearRange(1);
var min = new Date(minDateMaxDate[0] * 1000);
var max = new Date(minDateMaxDate[1] * 1000);
$(element).datepicker({
id: identifier,
firstDay: 1,
showOtherMonths: false,
selectOtherMonths: false,
changeYear: true,
changeMonth: true,
yearRange: getCalendarsYearRange(0),
monthNamesShort:monthNamesShort,
dayNamesShort:dayNamesShort,
minDate: min,
maxDate: max,
onClose: function (dateText, inst){
saveFieldsChanges(element,dateText,inst);
getFieldsFromDialog();
}
});
$(element).datepicker( "option", "dateFormat", "dd-mm-yy" );
$(element).datepicker( "option", "defaultDate", curdate );
$("#"+identifier+" .ui-datepicker-div .ui-datepicker-header .ui-datepicker-prev").live('click', function(){
console.log("prev");
});
$("#"+identifier+" .ui-datepicker-div .ui-datepicker-header .ui-datepicker-next").live('click', function(){
console.log("next");
});
}
Update
The html where I install datepicker is part of the xsl downloadable template, input fields are datepickers.
<div class="ferias-form-div">
<div class="labelfieldcontainer">
<div class="formlabels">Data inรญcio</div>
<div class="formfields">
<input type="text" id="datainicioferias" onblur="saveFieldsChanges(this)" onkeyup="saveFieldsChanges(this)" name="datainicioferias" value="" class="textbox"/>
<div class="errodialog" id="datainiciodialogferias"></div>
</div>
</div>
<div class="labelfieldcontainer">
<div class="formlabels">Data fim</div>
<div class="formfields">
<input type="text" id="datafinalferias" onblur="saveFieldsChanges(this)" onkeyup="saveFieldsChanges(this)" name="datafinalferias" value="" class="textbox"/>
<div class="errodialog" id="datafimdialogferias"></div>
</div>
</div>
...
This is how I installed datepicker, for example:
setDatepicker(inputelement,curdate,"datafinalferias");
UPDATE 2 - with the answer
With Alexander, I added this option to the calendar.
onChangeMonthYear: function (year, month, inst ) {
var limites;
var cal_date_string = month+'/'+year;
limites = getCalendarsYearRange(2);
var end_date_string = limites[1];
var start_date_string = limites[0];
if(end_date_string == cal_date_string){
setTimeout( function(){ $(".ui-datepicker-next").attr( "onclick", 'mensagemLimite(1);' )},100);
}
if(start_date_string == cal_date_string){
setTimeout( function(){ $(".ui-datepicker-prev").attr( "onclick", 'mensagemLimite(0);' )},100);
}
}
That way, when the prev / next button becomes inactive, it will get the onclick function that I want.