Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Whistlegreg is correct that you will need to override the twig form templates. However, you do not need to remove the <code>{% block generic_label %}</code> block. See his answer if you need help on how to override the templates.</p> <p>In order to wrap the checkbox input tags with a label, the first step will be to override the <code>{% block choice_widget %}</code> block and remove the <code>{{ form_label(child) }}</code> line from the <code>{% if expanded %}</code> section that prints out a separate label.</p> <pre><code>{% block choice_widget %} {% spaceless %} {% if expanded %} &lt;div {{ block('widget_container_attributes') }}&gt; {% for child in form %} {{ form_widget(child) }} {# {{ form_label(child) }} &lt;--------------------- remove this line #} {% endfor %} &lt;/div&gt; {% else %} &lt;select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}&gt; {% if empty_value is not none %} &lt;option value=""&gt;{{ empty_value|trans }}&lt;/option&gt; {% endif %} {% if preferred_choices|length &gt; 0 %} {% set options = preferred_choices %} {{ block('widget_choice_options') }} {% if choices|length &gt; 0 and separator is not none %} &lt;option disabled="disabled"&gt;{{ separator }}&lt;/option&gt; {% endif %} {% endif %} {% set options = choices %} {{ block('widget_choice_options') }} &lt;/select&gt; {% endif %} {% endspaceless %} {% endblock choice_widget %} </code></pre> <p>Now you will just need to handle printing the label in the <code>{% block checkbox_widget %}</code> block.</p> <pre><code>{% block checkbox_widget %} {% spaceless %} &lt;label for="{{ id }}"&gt;&lt;input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} /&gt;{{ label|trans }}&lt;/label&gt; {% endspaceless %} {% endblock checkbox_widget %} </code></pre> <p>You will need to do the same for <code>{% block radio_widget %}</code> since it would not otherwise have a label now.</p> <pre><code>{% block radio_widget %} {% spaceless %} &lt;label for="{{ id }}"&gt;&lt;input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} /&gt;{{ label|trans }}&lt;/label&gt; {% endspaceless %} {% endblock radio_widget %} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload