I have the following code:
function showDatePicker(){
var isEnabled=#{bean.isEnabled()};
if (isEnabled){
jQueryForDatepicker(".calendar").datepicker('enable');
jQueryForDatepicker(".calendar").datepicker({
changeMonth: true,
changeYear: true,
showOn: "button",
dateFormat:'yy-mm-dd',
buttonImage: "../resources/calendar.gif",
buttonImageOnly: true,
buttonText: "Select date",
beforeShow: function (input, inst) {
var rect = input.getBoundingClientRect();
setTimeout(function () {
inst.dpDiv.css({ marginTop: -input.offsetHeight + '10' , marginLeft: input.offsetWidth + '10' });
}, 0);
}
});
} else {
jQueryForDatepicker(".calendar").datepicker('disable');
}
}
The function is called from an ajax event, that is tied to a drop-down list. The drop-down contains the "enable", "disable" values, and sets the attribute in the managed bean. My problem is that, in the javascript function the var isEnabled is only set when the page is loaded. Initially is set to false, after that, if I change the value in drop-down, the variable in the javascript doesn't get updated, even though my bean sends the correct value back. So if it loads with false value, it stays that way even though it should update to true, or vice-versa.