JQuery UI Datepicker: Show all 12 months in <select> for current year?

I am using jQuery UI Datepicker with these parameters:

$('#birth_date').datepicker({ changeMonth: true, changeYear: true, minDate: new Date(-2206281600*1000), maxDate: new Date(1298653687*1000), yearRange: '1900:2011' }); 

It works well. Month and year are displayed as 2 side by side <select> . The problem is that we are only in February 2011. Therefore, when the user enters his date of birth to say that Dec, this month is not yet available. They must choose their year before the month becomes available.

How can I display all 12 months, even if these months are not valid for the current year?

+4
source share
2 answers

For those still looking, I decided to use defaultDate to fix this:

 $( ".selector" ).datepicker({ changeMonth: true, changeYear: true, minDate: '-100Y', //100 Years Old maxDate: '0' //Today defaultDate: '-1Y', //Default to One Year Ago to show 12 months yearRange: '-100:+0' //Show 100 }); 

It still limits the date range, so no one can choose a date in the future and does not rely on user input in a specific order.

+2
source

Use numberOfMonths to display all 12 months.

 $('#birth_date').datepicker({ numberOfMonths: 12 }); 
0
source

Source: https://habr.com/ru/post/1341332/


All Articles