2016-05-16 11 views
-2

ich habe ein Problem mit der Anpassung des Stils meiner Form der .. erweitere ich das Formular Widget in dieser normalen Art und Weise:Formular Zweig anpassen Stil

{{ form_label(form.tipi) }} 
{{ form_errors(form.tipi) }} 
{{ form_widget(form.tipi) }} 

Aber ich erhalte diese schlechten HTML:

<div id="requests_tipi" class="form-control scroll-select"> 
    <input type="checkbox" id="requests_tipi_1" name="requests[tipi][]" value="1" checked="checked"> 
    <label for="requests_tipi_1">Appartamento</label> 
    <input type="checkbox" id="requests_tipi_2" name="requests[tipi][]" value="2" checked="checked"> 
    <label for="requests_tipi_2">Casa Colonica</label> 
    <input type="checkbox" id="requests_tipi_3" name="requests[tipi][]" value="3" checked="checked"> 
    <label for="requests_tipi_3">Garage</label> 
    <input type="checkbox" id="requests_tipi_4" name="requests[tipi][]" value="4"> 
    <label for="requests_tipi_4">Loft</label> 
</div> 

würde ich eine Liste wie folgt aus:

<ul> 
    <li><label for="requests_tipi_1">Appartamento</label><input type="checkbox" id="requests_tipi_1" name="requests[tipi][]" value="1" checked="checked"></li> 
... 
</ul> 

Wie kann ich für mein Symfony-Formular anpassen ???

Dank

Antwort

1

Dies ist, wie Sie Rendering für einzelnes Feld (tipi in Ihrem Fall) anpassen:

http://symfony.com/doc/current/cookbook/form/form_customization.html#how-to-customize-an-individual-field

und das ist, wo die ursprüngliche Formatierung definiert ist (und wo Sie ein nehmen können " Inspiration“:):

https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig#L45

Also, so etwas wie Dies könnte funktionieren (bitte beachten Sie, dass ich nicht getestet habe, es könnte erforderlich sein, angepasst werden), einfach folgenden Code irgendwo an der Spitze der Vorlage-Datei:

{% form_theme form _self %} 

{% block _requests_tipi_widget %} 
    <ul {{ block('widget_container_attributes') }}> 
    {% for child in form %} 
     <li> 
     {{ form_label(child, null, {translation_domain: choice_translation_domain}) }} 
     {{ form_widget(child) }} 
     </li> 
    {% endfor %} 
    </ul> 
{% endblock _requests_tipi_widget %}