php - Symfony2 changing forms date input class in twig -


i confused on how can overwrite code of forms template match needs.. example when create date input fields long , want change class. reading documentation http://symfony.com/doc/current/cookbook/form/form_customization.html have no clue on how use example needs: did:

i added horizontal theme in config.yml:

# twig configuration twig:     debug:            "%kernel.debug%"     strict_variables: "%kernel.debug%"     form:         resources:              - 'bootstrap_3_horizontal_layout.html.twig'  

this how make data field input:

>add('dateofbirth', 'date', array(     'label' => 'date of birth * ',     'widget' => 'choice',     'attr' => array('placeholder' => 'date of birth'))) 

it renders template:

<div id="form_dateofbirth" placeholder="date of birth" class="form-inline">     <select id="form_dateofbirth_month" name="form[dateofbirth][month]" class="form-control"></select> 

i need change class in selected this:

<div id="form_dateofbirth" placeholder="date of birth" class="form-inline">      <select id="form_dateofbirth_month" name="form[dateofbirth][month]" class="span1"></select> 

how can this? documentation thing know need this:

{% form_theme form _self %}  {% block date_widget %}  {% endblock date_widget %}    {{ form(form) }} 

and what? ;/

i trying this:

{% block date_widget -%}             {% set attr = attr|merge({class: (attr.class|default('') ~ ' span1')|trim}) -%}      {%- endblock date_widget %} 

but getting undefined variable attr... ;/

update

the code: {{ form_widget(form.dateofbirth, {'attr': {'class': 'span1'}}) }} not need.

this changes class of whole div. need change class of field select, has class form-control

this (class="span1 form-inline"):

<div id="form_dateofbirth" class="span1 form-inline"><select id="form_dateofbirth_month" name="form[dateofbirth][month]" class="form-control"></select></div> 

overriding whole widget means change affect every other form. if need in other template long input? can add classes input individually. instance this:

that in formtype class

->add('dateofbirth', 'date', array(     'label' => 'date of birth * ',     'widget' => 'choice',     'attr' => array(         'placeholder' => 'date of birth',         'class' => 'your_custom_css_class' // add more if needed     )) ) 

or

that in twig template instance

{{ form_widget(form.birthdate, { 'attr': {'class': 'your_class'} }) }} 

you can apply customizations specific field of form. more on subject can read here.

- update -

take @ this answer on stackoverflow


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -