Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jquery ui datepicker IE focus fix
/*
After jquery ui datepicker selection, blur and change
events fire before focus is returned to the input field,
handling a quirk from IE browsers
*/
$("input.dateInput").datepicker({
changeMonth: true,
changeYear: true,
showAnim: "fadeIn",
yearRange: 'c-30:c+30',
showButtonPanel: true,
/* fix buggy IE focus functionality */
fixFocusIE: false,
/* blur needed to correctly handle placeholder text */
onSelect: function(dateText, inst) {
this.fixFocusIE = true;
$(this).blur().change().focus();
},
onClose: function(dateText, inst) {
this.fixFocusIE = true;
this.focus();
},
beforeShow: function(input, inst) {
var result = $.browser.msie ? !this.fixFocusIE : true;
this.fixFocusIE = false;
return result;
}
});
@progmars
Copy link

There seems to be still one problem on IE with this: if you navigate with Tab through fields, then each second focus on datepicker field will not work. Tested on IE12.

@jeffsheets
Copy link
Author

@progmars interesting, thanks for the info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment