Skip to content

Instantly share code, notes, and snippets.

@gcapnias
Forked from jeffsheets/datepicker-focus.js
Last active December 18, 2015 21:39
Show Gist options
  • Select an option

  • Save gcapnias/5849057 to your computer and use it in GitHub Desktop.

Select an option

Save gcapnias/5849057 to your computer and use it in GitHub Desktop.
jQuery 1.9.x for $.browser missing fix - Chrome 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 & Chrome
*/
$("input.dateInput").datepicker({
changeMonth: true,
changeYear: true,
showAnim: "fadeIn",
yearRange: 'c-30:c+30',
showButtonPanel: true,
/* fix buggy focus functionality */
fixFocus: false,
/* blur needed to correctly handle placeholder text */
onSelect: function (value, instance) {
this.fixFocus = true;
$(this).blur().change().focus();
},
onClose: function (value, instance) {
this.fixFocus = true;
this.focus();
},
beforeShow: function (input, instance) {
var result = (navigator.userAgent.indexOf('MSIE') > 0 || navigator.userAgent.indexOf('Chrome') > 0) ? !this.fixFocus : true;
this.fixFocus = false;
return result;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment