Tuesday, February 22, 2011

jQuery datepicker show only month and year

This code from: http://stackoverflow.com/questions/2208480/jquery-date-picker-to-show-month-year-only
seems to work:
---------------
[script]
$(function() {
$('.date-picker').datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
});
[/script]
-----------
But the main problem is showing back the month,year in the dialog box.To do that, you will have to modify the jquery.ui.datepicker.js

with the code (line #1548, #1549):
----------------
var date = this._daylightSavingAdjust(new Date(year, month - 1, (day >= 1 ? day: 1)));
if (date.getFullYear() != year || date.getMonth() + 1 != month || (day > 0 && date.getDate() != day))
----------------

No comments: