Jquery UI datepicker seems to disregard the "readonly" attribute of input fields.
In the code below, I'm able to disable the popup calendar by using the "beforeShow" event (thanks to another answer on StackOverflow - reproduced here for others' benefit)
However, I can't prevent the Enter key from populating the textbox with the current date. I tried intercepting the "keydown" event (below) but no joy. :-(
<input type="text" class=".input-date" readonly="readonly" />
$(".input-date").datepicker({
beforeShow: function (input, inst) {
if ($(input).attr("readonly")) {
inst.dpDiv = $('<div style="display: none;"></div>');
}
}
})
.bind("keydown", function (e) {
if (e.keyCode == 13 && $(this).attr("readonly") == "readonly") {
e.preventDefault();
e.stopPropagation();
return false;
}
})
Also FWIW: The date field's "readonly" is turned on & off dynamically on my page, so I can't just not apply the datepicker plugin to readonly fields.
Any suggestions?