0

I am having issues overriding a label in my form in my Symfony 4.4 application:

{{ form_row(form.legal, {
   'label' : 'personal.form.fields.legal'|trans
}) }}

personal.form.fields.legal looks like this:

I agree that I am 18 and above, I have read and accept the <a href="/terms-cond">T&Cs</a>

My form definition:

 ->add('legal', CheckboxType::class,
   'required' => true,
   'mapped' => false,
])

My attempt at overriding this label is this:

{% block _crmbundle_personal_legal_label %}
    <label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %} style="color: red;">
        {{ form_widget(form) }}
        {{ label|unescape|raw }}
    </label>
{%- endblock %}

I have a Twig extension that does this:

    public function getFilters(): array
    {
        return [
            new TwigFilter('unescape', function ($value) {
                return html_entity_decode($value);
            }),
        ];
    }

I am finding this duplicates the label and I can't find a way to correct this. I have one checkbox, but two labels (both showing in red)

crmpicco
  • 16,605
  • 26
  • 134
  • 210
  • Are you using `CheckboxType` or `ChoiceType` with the `expanded: true` and `multiple: true` option? Also what is your `{% form_theme %}` tag? – Will B. Mar 31 '21 at 03:38
  • @WillB. Thanks for the comment. I'm using `CheckboxType` and have updated the question with my form field defintion. I have `{% form_theme form _self %}` at the top of the template. – crmpicco Mar 31 '21 at 03:51
  • To prevent the duplicate rendering of the block you need to move your `{% block _crmbundle_personal_legal_label %}` to a separate file than that of the `{{ form_start(form) }}` and set `{% form_theme form 'path/to/form.theme.twig' %}` and optionally extend a base Symfony form. – Will B. Mar 31 '21 at 12:23
  • Does this answer your question? [Twig form\_theme \_self customizing individual field](https://stackoverflow.com/questions/21422038/twig-form-theme-self-customizing-individual-field) – Will B. Mar 31 '21 at 12:23

0 Answers0