Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI: Datepicker set year range dropdown to 100 years

Using the Datepicker the year drop down by default shows only 10 years. The user has to click the last year in order to get more years added.

How can we set the initial range to be 100 years so that the user will see a large list by default?

enter image description here

    function InitDatePickers() {         $(".datepicker").datepicker({             changeMonth: true,             changeYear: true,             showButtonPanel: true,             maxDate: '@maxDate',             minDate: '@minDate'         });     } 
like image 395
Ian Vink Avatar asked Dec 13 '12 17:12

Ian Vink


People also ask

How can change date format in jQuery ui Datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How do I set a Datepicker range?

To set date range of one month from current date, we will use 'M' option to "+1" for maxDate and for minDate "0" So the current date becomes the value of minDate.

How do I change my Datepicker size?

By default DatePicker has standard height and width (height: '30px' and width: '143px'). You can change this height and width by using height and width property respectively. $(function () { // creates DatePicker from input $("#datePicker").


1 Answers

You can set the year range using this option per documentation here http://api.jqueryui.com/datepicker/#option-yearRange

yearRange: '1950:2013', // specifying a hard coded year range 

or this way

yearRange: "-100:+0", // last hundred years 

From the Docs

Default: "c-10:c+10"

The range of years displayed in the year drop-down: either relative to today's year ("-nn:+nn"), relative to the currently selected year ("c-nn:c+nn"), absolute ("nnnn:nnnn"), or combinations of these formats ("nnnn:-nn"). Note that this option only affects what appears in the drop-down, to restrict which dates may be selected use the minDate and/or maxDate options.

like image 88
wirey00 Avatar answered Sep 21 '22 17:09

wirey00