Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set minimum year value in Sonata Admin Bundle date form field

I'm using Sonata Admin Bundle with Symfony2. I have a datetime field. This is my piece of code. Pretty simple.

->add('passportIssueDate', 'date')

But in the form I can select Year value only from 2008 to 2018. Is there a way to set different range? Thanks in advance.

like image 701
Sergei Kutanov Avatar asked Oct 30 '13 13:10

Sergei Kutanov


1 Answers

You would use something like this:

$builder->add('dob', 'birthday', array('years' => range(1980, date('Y')), 'format' => 'dd-MMMM-yyyy'));

This means the Date Field (regardless of if it's DateTime, Date, or Birthday) will give you a range from 1980 in this case to the current year. To get a range including years in the future, you would use something like this:

$builder->add('startDate', 'date', array('years' => range(2012, 2020), 'format' => 'dd-MMMM-yyyy'));

This instance gives you a range from 2012 to 2010.

Furthermore, the 'format' => 'dd-MMMM-yyyy' will format your date selection.

like image 118
mickburkejnr Avatar answered Oct 24 '22 06:10

mickburkejnr