Skip to content

Instantly share code, notes, and snippets.

@alab1001101
Created April 17, 2012 20:34
Show Gist options
  • Save alab1001101/2408818 to your computer and use it in GitHub Desktop.
Save alab1001101/2408818 to your computer and use it in GitHub Desktop.
Month and Year only Jquery.datepicker
$(function(){
$('.monthyearpicker').datepicker({
dateFormat: 'mm.yy',
changeMonth: true,
changeYear: true,
durration: 0,
beforeShow: function(input, instance) {
var dates = instance.input.val().split('.'),
nows = $.datepicker.formatDate('mm.yy.dd', new Date()).split('.');
$.extend(dates, {
0: dates[0] && dates[0].length == 2 ? dates[0] : nows[0],
1: dates[1] && dates[1].length == 4 ? dates[1] : nows[1],
2: '01',
length: 3
});
instance.settings.defaultDate = $.datepicker.parseDate('mm.yy.dd', dates.join('.'));
instance.dpDiv.addClass('hide-calendar');
},
onChangeMonthYear: function(year, month, instance) {
$(this).datepicker('setDate', $.datepicker.parseDate('mm.yy.dd', [month, year, '01'].join('.')));
},
onClose: function(dateText, instance) {
instance.dpDiv.css('display', 'none').removeClass('hide-calendar');
}
});
$('.datepicker').datepicker();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment