Last active
August 29, 2015 14:06
-
-
Save sahibalejandro/8a37d41d930753234127 to your computer and use it in GitHub Desktop.
Setup defaultDate from altField on jQuery UI datepickers.
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
/** | |
* 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