-
-
Save sinelaw/5416130 to your computer and use it in GitHub Desktop.
/* | |
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; | |
} | |
}); | |
} |
Quick and easy fix. Big thanks!
Thanks!
didn't worked on mine jQuery 1.11.2 and ui 1.11.4
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:
initDatePicker: function ()
{
// Initialize datepicker
var qs = document.getElementsByClassName("datepick");
for (var i = 0; i < qs.length; ++i)
{
$(qs[i]).datepicker(
{
// showOn: "button"
// showOn: "both"
showOn: "focus"
, buttonImage: "../images/cal.gif"
, buttonImageOnly: true
//, buttonImageOnly: false
, dateFormat: 'dd.mm.yy'
, changeMonth: true
, changeYear: true
, showWeek: false // true
, firstDay: 1
, showOtherMonths: true //false
, selectOtherMonths: true
, showButtonPanel: true
//,onSelect : function(x, u){
// // $(this).focus();
// window.setTimeout(function () { $("#txtSchulungsTyp").focus(); $(this).datepicker("hide"); }, 300);
//},
//onClose: function(e){
// // e.preventDefault();
// e.preventDefault ? e.preventDefault() : e.returnValue = false;
// return false;
//}
, onSelect: function ()
{
$(this).datepicker('disable');
}
, onClose: function ()
{
window.setTimeout(function (e)
{
$(e).datepicker('enable')
}.bind(undefined, this), 500)
}
})
; // End datepicker
// console.log(mGlobalLanguage);
// $(qs[i]).datepicker("option", $.datepicker.regional['de']);
// $(qs[i]).datepicker("option", $.datepicker.regional['FR']);
} // Next i
}
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
Thanks!