-
-
Save sinelaw/5416130 to your computer and use it in GitHub Desktop.
Fixes reopening of datepicker on IE <= 9 (not tested on IE 10) Changes to work for jQuery 1.9.1 and jQuery-ui 1.10.1:
1. don't use $.browser since it's deprecate. Instead use a var called isIE
2. simplify the handlers
3. use $.datepicker.setDefaults to affect ALL datepickers on the page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
After jquery ui datepicker selection, blur and change | |
events fire before focus is returned to the input field, | |
handling a quirk from IE browsers | |
*/ | |
function setupDatepicker() { | |
// 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; | |
} | |
}); | |
} |
thanks @ststeiger for IE11 i can resolve my problem now :)
In case anyone has to run on an older jquery version, like me (1.11.1):
The original post's check for IE did not work for me and so I replaced it with
var userAgent = window.navigator.userAgent;
var msie = userAgent.indexOf('Trident/7.0');
var isIE = (msie !== -1) ? true : false;
If you need to tweak the search string to your needs, see if this thread can help
Note though, that browser sniffing via userAgent is usually not recommended, see MDN
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Necromancing.
I had the same problem, except this answer didn't work.
It may be because the code I have to work on works with iframes, but I don't now for sure.
On top, I couldn't update to the latest version, because it would break compatibility with the rest of the project I had to work on.
So this is what fixed it for me: