Hi I'm new to Symfony and I have the following problem:
I'm implementing a rate form so I added a radio button group so select a value from 1 to 5. The idea is yo show five stars instead of the classic radio buttons so I need to add a class to each input field.
The problem is that symfony adds the class to the hole radio group and not each input.
I searched for a solution and the closest hint I found was this:
{% block choice_widget_expanded %}
{% spaceless %}
<div {{ block('widget_container_attributes') }}>
{% for child in form %}
{{ form_widget(child, {'attr': {'class': 'rating-input'}}) }}
{% endfor %}
</div>
{% endspaceless %}
{% endblock choice_widget_expanded %}
The code above also wraps the radio group on a div with the class 'rating-input'.
This is the test form code in the controller:
$form->createFormBuilder()
->add('rate', 'choice', array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5), 'expanded' => true, 'multiple' => false))
->add('save', 'submit')
->getForm();
Here's a sample image of the html I got:
Any ideas how can I achieve what I want?
Thanks in advance.