Reputation: 4186
I am trying to alter the date_widget using symfony2 and twig. By default a field of years has 10 year options, e.g. 5 years before and 5 years after the today date. I would like just the years until now. How can I change it? I have already looked at 'form_div_layout.html.twig' but I see that it's not the place of this.
Upvotes: 2
Views: 10434
Reputation: 5280
Use the 'years' option when building your date widget. For example:
$builder->add('foobar_date','date', array(
'years' => range(date('Y') -5, date('Y')),
));
More info on how to configure the date widget: http://symfony.com/doc/current/reference/forms/types/date.html
(edited)
Upvotes: 17