Well, I have a form and one field is the age. Because of this I set the att yearRange to solve my problems. And it solve them. However I lost one functionality:
1 - Before I set the yearRange, when I'd select one year the range were updated to a new range, for example: the year is 2012 and yearRange is -10:+10 (by default), this way the biggest year is 2022 and the oldest year is 2002. After that, when I select the year 2002, the range is updated: the biggest will be 2012 and the oldest will be 1992.
2 - In my case, I need to set the yearRange to define a range and then, when I select a new year the range will be updated, like: first the year is 2012 and the yearRange is -50, after I select 1962 and I wish the range was updated to at least 50 years, for example.
Below the code where I set the yearRange:
function load_datepicker(){
$('.datepicker_birth').datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
showOn: 'button',
yearRange: '-50 :c',
Lookup how the yearRange Option works here.
You want to set the yearRange relative to the currently selected year by doing something like "c-nn:c+nn"
Update your initialization accordingly:
$('input').datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
showOn: 'button',
yearRange: 'c-50:c',
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With