Skip to content

Instantly share code, notes, and snippets.

@antontjea
Created October 3, 2012 13:11
Show Gist options
  • Save antontjea/3826826 to your computer and use it in GitHub Desktop.
Save antontjea/3826826 to your computer and use it in GitHub Desktop.
How to use jQuery UI datepicker instead of default HTML5 date picker
$(document).ready(function () {
loaddatepicker();
});
$(document).ajaxComplete(function () {
loaddatepicker();
});
function loaddatepicker() {
//Only if it's a non touch device.
if (!Modernizr.touch) {
if (Modernizr.inputtypes.date) {
//Disable default html5 datepicker
$('input[type=date]').on('click', function(event) {
event.preventDefault();
});
//Enable jquery-ui date time picker
$('input[type="date"]').datepicker({
dateFormat: 'yy-mm-dd'
});
} else {
if (!Modernizr.inputtypes.date) {
//This happens if device is touch and
//does not support html5 date time
$('input[type="date"]').datepicker({
dateFormat: 'yy-mm-dd'
});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment