-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Description
I'm looking for a way to display a message next to the label of individual radio buttons (RadioType, i.e. ChoiceType expanded). I think this is the only type of widgets for which Symfony doesn't yet offer a nice way to customize their rendering.
Here's my idea:
Since there are 100 ways of how/where to exactly display that "message" (info, data, whatever), a one-size-fits-all approach probably won't work. So the users will have to adapt their form theme in any case. The question is: How to pass the data to the form template?
Status quo:
If you loop over the field's choices in Twig, you can pass an arbitrary field name:
{% for radio in form.gender %}
{{ form_widget(radio, {'foo':'bar'}) }} {# But how can we add this to just *some* choices? #}
{% endfor %}
...and then take care of this foo
field in your form theme.
Proposed solution:
Allow adding custom data to the choices
array in the FormType. How could this be done? Right now, choices is an array in the form [label=>value]. Suggestion:
'choices' => [
['label' => 'Female', 'value' => 'f', 'custom/help/payload' => 'whatever'],
[...],
],
This would give the user a clean way to pass information to the form theme. The actual rendering is left to the theme.