Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maxDate option in datepicker

I have a Jquery UI datepicker like this.

enter image description here
I can only select month and year from the datepicker.
code:

$('#datepicker').datepicker({
     changeMonth: true,
     changeYear: true,
     showButtonPanel: true,
     dateFormat: 'M yy',
     maxDate: '0',                      
     onClose: function() {
          var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
          var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
          $(this).datepicker('setDate', new Date(iYear, iMonth, 1));                              
    },
     beforeShow: function(input, inst) {
          $(inst.dpDiv).addClass('calendar-off');                             
     }
});

If I set maxDate: '0' the maximum month and year I can select is the current month and current year.
I want to set the maximum month and year using jquery. For a normal datepicker with date,month,year, first I remove this maxDate: '0'code and I used the following code to set the maximum date

var maximumDate = '07-15-2013';
$("#datepicker" ).datepicker( "option", "maxDate", maximumDate);

How can i set the maximum date in month and year picker? The above code is not working in this case.Please give me your suggestions.

like image 899
Nandu Avatar asked Jul 15 '13 05:07

Nandu


1 Answers

Tried the following code.It works fine for me.

    var date = new Date("2013-07-15");
    var currentMonth = date.getMonth();
    var currentDate = date.getDate();
    var currentYear = date.getFullYear();
    $("#datepicker" ).datepicker( "option", "maxDate", new Date(currentYear, currentMonth, currentDate));

Example fiddle I created:FIDDLE

like image 136
Nandu Avatar answered Oct 17 '22 00:10

Nandu