How can I set the HTML
class
attribute to a form <input>
using the FormBuilder
in Symfony2
?
Something like this:
->add('birthdate', 'date',array(
'input' => 'datetime',
'widget' => 'single_text',
'attr' => array(
'class' => 'calendar'
)
))
{{ form_widget(form.birthdate) }}
I want this input
field with the attribute class
set to calendar
You can do this from the twig template:
{{ form_widget(form.birthdate, { 'attr': {'class': 'calendar'} }) }}
From http://symfony.com/doc/current/book/forms.html#rendering-each-field-by-hand
You can do it with FormBuilder. Add this to the array in your FormBuilder:
'attr'=> array('class'=>'span2')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With