How to disable future month and year in monthpicker

I am using the month picker, I want to restrict users to select future months and years. How can I achieve this? I tried to use

$("#month").monthpicker({ dateFormat: 'M-yy',
            autoSize: true,
            changeYear: true,
            changeMonth: true,
            showButtonPanel: true,   
            maxDate: new Date().getMonth()

});

      

but with this I could only limit the next year, I can still choose the next month. Any help would be appreciated.

+3


source to share


1 answer


By default, the year range starts 10 years ago and ends 10 years later if the current year is selected.

This and other settings can be overwritten when the widget is initialized:

options = {
pattern: 'yyyy-mm', // Default is 'mm/yyyy' and separator char is not mandatory
selectedYear: 2010,
startYear: 2008,
finalYear: 2012,
monthNames: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez']

      

};



$('#custom_widget').monthpicker(options);

      

You can try this. This works for me.

$('#my_widget').monthpicker('disableMonths', [1, 2, 11, 12]);
$('#my_widget').monthpicker('disableMonths', []); // re-enables all months

      

Reference By: Month Picker Jquery

0


source







All Articles