Arnaud Ncy Arnaud Ncy - 28 days ago 10
Twig Question

symfony2 customize form datetime rendering

I have a form with a datetime rendered as 5 select inputs d MM YYYY H-i

$builder
->add('date', 'datetime',
array(
'data' => new \DateTime('now'), //default value
'format' => 'd-MM-yyyy H-i-s',
'years' => array(2016, 2017),
)
)
->getForm();


enter image description here

I would like to customize the template and hide the character ":" between the minutes and seconds select inputs. How can I achieve this?

Answer

I finally found the solution. The datetime field can be rendered as more select inputs in twig template like this:

{{ form_widget(form.date.date.day) }}
{{ form_widget(form.date.date.month) }}
{{ form_widget(form.date.date.year) }}
{{ form_widget(form.date.time.hour) }}
{{ form_widget(form.date.time.minute) }}