1

I saw this JQuery Monthpicker that really helped me. jQuery UI DatePicker to show month year only

But I now need the monthpicker to display only the last two months in the options, apart from the current month.

Eg. Since the current month is June 2014, The monthpicker should display only May and April 2014, apart from June.

Can someone help me out here?

Community
  • 1
  • 1
user3270763
  • 125
  • 1
  • 3
  • 13
  • Sadly, it doesn't look like the [`numberOfMonths` option](http://jqueryui.com/datepicker/#multiple-calendars) plays nicely with `changeMonth` and `changeYear`: http://jsfiddle.net/DBpJe/3468/ – T.J. Crowder Jun 27 '14 at 09:07

1 Answers1

0

Set the minDate and maxDate properties on the object being passed as an argument to the datepicker function:

$("#picker").datepicker({
    minDate: "-2m",
    maxDate: 0,
    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));
    }
});

JS Fiddle: http://jsfiddle.net/aRfTr/1/

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189