Datepicker only shows last 10 years

Permalink 1 user found helpful
I'd like to use the datepicker to have someone choose their date of birth but the date picker only shows +/- ten years from the current year. I realize you can just type in the year yourself in the input box, but I would like additional past years to show in the drop down as well - anyone know where I can find this in order to modify it?

hursey013
View Replies: View Best Answer
tomreitz replied on at Permalink Best Answer Reply
tomreitz
I haven't tested this, but you could try adding
yearRange: \'c-100:c+0\'

to the argument list of the datepicker() calls in <site_root>/concrete/helpers/form/date_time.php (lines 141 and 198).


of course you'll probably loose this change next time you update C5.
hursey013 replied on at Permalink Reply
hursey013
That did it - thank you.
meinprotein replied on at Permalink Reply
Hello

For me too, that worked - but not a long time. After 20 sec and without any manipulation the behaviour returned to the old way!!!

can anybody help???

thanks
Dan, switzerland (sorry 4 my bad english)
meinprotein replied on at Permalink Reply
Again me. It was a simpel caching-problem. Solved!

thanks @ tom reitz!!!
Mnkras replied on at Permalink Reply
Mnkras
copy the file to /helpers and name the class SiteDateTimeHelper instead of DateTimeHelper
bjwebdesign replied on at Permalink Reply
Does it matter where in that line you put the code?
tomreitz replied on at Permalink Reply
tomreitz
It does - here's line 141:
$html .= '<script type="text/javascript">$(function() { $("#' . $id . '_dt").datepicker({ changeYear: true, showAnim: \'fadeIn\' }); });</script>';

which should become
$html .= '<script type="text/javascript">$(function() { $("#' . $id . '_dt").datepicker({ changeYear: true, showAnim: \'fadeIn\', yearRange: \'c-100:c+0\' }); });</script>';

and here's line 198:
$html .= '<script type="text/javascript">$(function() { $("#' . $id . '").datepicker({ changeYear: true, showAnim: \'fadeIn\' }); });</script>';

which similarly needs to become
$html .= '<script type="text/javascript">$(function() { $("#' . $id . '").datepicker({ changeYear: true, showAnim: \'fadeIn\', yearRange: \'c-100:c+0\' }); });</script>';

Hope this helps!
bjwebdesign replied on at Permalink Reply
Strange. I still can't get this code to work.
tomreitz replied on at Permalink Reply
tomreitz
flush your C5 cache and your browser cache? meinprotein apparently got it working.

Concrete5 could be using <site_root>/helpers/form/date_time.php instead of <site_root>/concrete5/helpers/form/date_time.php, if it exists.
aleamio replied on at Permalink Reply
This post referred to here worked but the line code number has changed in 5.6.3.1


In the 5.6.3.1 open <site_root>/concrete/helpers/form/date_time.php. If you only see few lines of code it means you opened the wrong one. Look for the correct one -- it is there.

The original line 152 reads:
if ($calendarAutoStart) { 
         $html .= '<script type="text/javascript">$(function() { $("#' . $id . '_dt").datepicker({ dateFormat: \'' . DATE_APP_DATE_PICKER . '\', changeYear: true, showAnim: \'fadeIn\' }); });</script>';


Replaced with this one:
if ($calendarAutoStart) { 
         $html .= '<script type="text/javascript">$(function() { $("#' . $id . '_dt").datepicker({ dateFormat: \'' . DATE_APP_DATE_PICKER . '\', changeYear: true, showAnim: \'fadeIn\', yearRange: \'c-100:c+0\' }); });</script>';


Line 209 that reads:

if ($calendarAutoStart) { 
         $html .= '<script type="text/javascript">$(function() { $("#' . $id . '").datepicker({ dateFormat: \'' . DATE_APP_DATE_PICKER . '\', changeYear: true, showAnim: \'fadeIn\' }); });</script>';


Replace with the same code as done earlier:

if ($calendarAutoStart) { 
         $html .= '<script type="text/javascript">$(function() { $("#' . $id . '_dt").datepicker({ dateFormat: \'' . DATE_APP_DATE_PICKER . '\', changeYear: true, showAnim: \'fadeIn\', yearRange: \'c-100:c+0\' }); });</script>';
Twoez replied on at Permalink Reply
Although this is an expired topic, i would like to make an addition to it. I was also experiencing problems with the datetime-picker and its limited year range.

For me the suggested solution didn't work, because it changes the year range according to the year you select - 100 years. Meaning that when I select the year 1913 the range will be from 1813 - 1913. Years higher than 1913 dissapear, and there seems to be no way back.

What I used is:
yearRange: "-100:+0"

In case anyone else is experiencing the same problem i'd like to share it.
JD46 replied on at Permalink Reply
Thanks for sharing, I have the same problem this should help!
gmatik replied on at Permalink Reply
gmatik
Where are the date_time.php files in 5.6.2.1?

I only have 22 lines in that file.
gmatik replied on at Permalink Reply
gmatik
http://www.concrete5.org/community/forums/customizing_c5/date-picker-year-range/#506233