Skip to content

Instantly share code, notes, and snippets.

@software-mariodiana
Forked from sinelaw/datepicker-focus.js
Created December 12, 2014 14:19
Show Gist options
  • Save software-mariodiana/b39829c602b1d5a06d2a to your computer and use it in GitHub Desktop.
Save software-mariodiana/b39829c602b1d5a06d2a to your computer and use it in GitHub Desktop.
Fix IE bug for datepicker reopening. (I am not sure if this works on modern IE versions.)
/**********************************************************
* Hack to fix datepicker issue in IE.
*
* https://gist.github.com/sinelaw/5416130
**********************************************************
*
* After jquery ui datepicker selection, blur and change
* events fire before focus is returned to the input field,
* handling a quirk from IE browsers
*/
var setupDatepickerIEHack = function() {
// The 'isIE' var below requires an '.old-ie' class to be set on the html,
// for example:
// <!--[if lt IE 7]> <html class="old-ie lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
// <!--[if IE 7]> <html class="old-ie ie7 lt-ie9 lt-ie8"> <![endif]-->
// <!--[if IE 8]> <html class="old-ie ie8 lt-ie9"> <![endif]-->
// <!--[if IE 9]> <html class="old-ie ie9"> <![endif]-->
// <!--[if (gt IE 9)|!(IE)]><!--> <html class="" lang="en"> <!--<![endif]-->
var isIE = 0 < $('html.old-ie').length;
$.datepicker.setDefaults({
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;
},
onClose: function(dateText, inst) {
this.fixFocusIE = true;
},
beforeShow: function(input, inst) {
var result = isIE ? !this.fixFocusIE : true;
this.fixFocusIE = false;
return result;
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment