Created
October 3, 2012 13:11
-
-
Save antontjea/3826826 to your computer and use it in GitHub Desktop.
How to use jQuery UI datepicker instead of default HTML5 date picker
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
$(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