datepicker - reverse year range order
Hello,
I needed to reverse year range order when changeYear option was true. I've implemented an easy solution. In jquery.ui.datepicker.js's _generateMonthYearHeader method, just change:
- for (; year <= endYear; year++) {
- html += '<option value="' + year + '"' +
- (year == drawYear ? ' selected="selected"' : '') +
- '>' + year + '</option>';
- }
for
- var reverseYearRange = this._get(inst, 'reverseYearRange');
- if(reverseYearRange){
- for (; year <= endYear; endYear--) {
- html += '<option value="' + endYear + '"' +
- (endYear == drawYear ? ' selected="selected"' : '') +
- '>' + endYear + '</option>';
- }
- }else{
- for (; year <= endYear; year++) {
- html += '<option value="' + year + '"' +
- (year == drawYear ? ' selected="selected"' : '') +
- '>' + year + '</option>';
- }
- }
Also, you must add default option at line 80:
- yearRange: 'c-10:c+10', // Range of years to display in drop-down,
- // either relative to today's year (-nn:+nn), relative to currently displayed year
- // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
- reverseYearRange: false, // true to display range of years in reverse order in drop-down
- showOtherMonths: false, // True to show dates in other months, false to leave blank
selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable
An example of use:
- $(document).ready(function() {
- $("#my-date-input").datepicker({
- changeYear: true,
- changeMonth: true,
- yearRange: '-100:-10',
- reverseYearRange: true,
- defaultDate: '-10y',
- });
- });
You could include this enhancement in new versions of jquery-ui-datepicker plugin.
Regards