I have this form that accepts dates from datepicker or you can input your own date by hand. I’m formatting any input date to match mm/dd/yyyy. I’m doing that off the blur but I ran into a problem that when I hit enter to run search right away the input doesn’t get formatted correctly thus throwing error. If I hit enter the date picker goes away. If I hit enter again then the input field hears it. The input field though will hear every other keydown while date picker is visible.
var $callSearchEndDate = $j('#call-search-end-date');
$callSearchEndDate.datepicker();
$callSearchEndDate.blur(function() {
if (!utility.isNotEmpty($callSearchEndDate.val())) {
$callSearchEndDate.datepicker('setDate', new Date());
}
$j(this).val(checkDate($j(this).val()));
}).bind('keypress', function(e){
var code = (e.keyCode ? e.keyCode : e.which);
console.log('key code = ' + code);
if(code === 13) {
$j(this).val(checkDate($j(this).val()));
}
});
Here is the answer. The date picker has its own event listening for when it closes. Thanks @TheZ