Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Created October 12, 2010 15:48
Show Gist options
  • Select an option

  • Save aaronmcadam/622404 to your computer and use it in GitHub Desktop.

Select an option

Save aaronmcadam/622404 to your computer and use it in GitHub Desktop.
Initialisation code for jQuery UI datepicker widget
$(document).ready(function() {
$('.datePicker').each(function(){
var $this = $(this); // cache the this object
$this.keydown( function(event){
if ( event.keyCode !== 9 ){ // If key is not Tab - for accessibility
event.preventDefault(); // Prevents user input, forces user to use Calendar Date Picker widget
}
})
.datepicker({
showOn : 'both', // displays Calendar widget on focus of input and on clicking the Calendar icon
buttonText : 'Choose a date', // Alt text for Calendar icon
buttonImage : '/includes/jqueryCalendar/cal.gif', // source to the Calendar button icon
buttonImageOnly : true, // only show the icon, not the buttonText
dateFormat : 'dd-mm-yy' // format of the date
});
$this.datepicker( "setDate" , new Date() ); // Prefills the input with the current date to stop form history showing up on click
});
});
@aaronmcadam
Copy link
Copy Markdown
Author

Initialisation code for jQuery UI datepicker widget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment