Skip to content

Instantly share code, notes, and snippets.

@sahibalejandro
Last active August 29, 2015 14:06
Show Gist options
  • Save sahibalejandro/8a37d41d930753234127 to your computer and use it in GitHub Desktop.
Save sahibalejandro/8a37d41d930753234127 to your computer and use it in GitHub Desktop.
Setup defaultDate from altField on jQuery UI datepickers.
/**
* Setup datepickers
*/
$('.datepicker').each(function ()
{
var alt_field = $(this).data('alt-field');
var altField = $(alt_field);
var defaultDate = new Date();
if (altField.val() != '') {
var date_parts = altField.val().split('-');
defaultDate.setFullYear(date_parts[0], date_parts[1] - 1, date_parts[2]);
}
return $(this).datepicker({
dateFormat: 'DD d, MM yy',
altFormat: 'yy-mm-dd',
altField: alt_field
}).datepicker('setDate', defaultDate);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment