Search code examples
symfonyradio-buttonsymfony-forms

Symfony 6 : Customize a form with radio buttons


I have a form and want to customize it with symfony :

<input type="radio" name="type" value="auto" onClick="getMarques('auto')" id="check1">
<label class="s-submitCheckLabel" for="check1"><span class="m-circle"></span></label>
<label class="s-submitCheck" for="check1">Auto</label>

I have tried this:

{% for child in formAnnonce.category %}
 
 {{ form_widget(child, {'attr' : {'class': 'form-check-input'}, {'name': 'type'}, {'id': 'check1'} }) }}
        {{ form_label(child)}}
        {{ form_help(child) }}
        {{ form_errors(child) }}



{% endfor %}  



Solution

  • {% for child in formAnnonce.category %} 
       {{ form_widget(child, {'attr': {'onclick': 'getMarques("' ~ child.vars.value~'")'}})}}
       <label class="s-submitCheckLabel" for="{{ child.vars.id }}"><span class="m-circle"> </span></label> 
       <label class="s-submitCheck" for="{{ child.vars.id }}">{{ child.vars.label </label> 
    {% endfor %}