0

Sorry folks, don't seem to find this in the manual, but I guess it must be there. I need to restrict the months shown on a UI datepicker to only May, June, July, August, September and October. I see lots of minDate and maxDate but they seem to set date ranges for minDate todate maxDate +3M etc. suggestions please.

  • 1
    Maybe this related post helps: http://stackoverflow.com/questions/2208480/jquery-date-picker-to-show-month-year-only – AquilaRapax May 30 '12 at 07:11

2 Answers2

2

OnChangeMonthYear is the event you want to attach to. You'll probably want to check if the month is out of your allowable month range, then reset the date to the first of the next allowable month in the next year.

$('.selector').datepicker({
    onChangeMonthYear: function(year, month, inst) {
    //0 based index on the months, from what I remember.
        if(month<4){
            year = year-1;
             $( this ).datepicker( "setDate" , new Date(year, 9, 1) )
             $( this ).datepicker("refresh");
        }

        if(month>9){
            year = year+1;
             $( this ).datepicker( "setDate" , new Date(year, 4, 1) )
             $( this ).datepicker("refresh");
        }

    }
});
Jason Kulatunga
  • 5,814
  • 1
  • 26
  • 50
0
var currentYear = (new Date).getFullYear();

$( ".selector" ).datepicker(
  { minDate: new Date(currentYear, month, day, hours, minutes, seconds, milliseconds), 
    maxDate: new Date(currentYear, month, day, hours, minutes, seconds, milliseconds) });

This should do it, not sure if it works. But gives the idea

Ghokun
  • 3,345
  • 3
  • 26
  • 30