Symfony date widget limit 5 years forward/backward + admin generator

You are not authorized to post comments.

I was creating a new project and I wanted to create on model Client a field called birthday as DATE field. I noticed that the admin generator form created a limited year's select to 5 forward and backward. I'm too change the format of field of mm/dd/yyyy to dd/mm/yyyy. How can I did it?

You need to override the formClass, like this:

class ClientForm extends BaseClientForm
{
  public function configure()
  {
    // create new values for years
    $years = range(date('Y') - 80, date('Y') + 80);
    $this['birthday']->getWidget()->setOption('years', array_combine($years, $years));
    
    // change the format of date
    $this['birthday']->getWidget()->setOption('format', '%day%/%month%/%year%');
    
  }
}