Symfony 8.2 New Published on

Help text under each choice, with choice_help

choice_help gives each radio button its own help text, linked by aria-describedby: short labels, and explanations that screen readers read with the right choice.

Topics covered: FormsAccessibility

New in Symfony 8.2 (in development). A ChoiceType expanded into radio buttons or checkboxes had only one label per choice. To explain a subscription plan, you had to glue the description to the label, or rewrite the form theme.

choice_help

The new option gives each choice its own help text. It's set like choice_label: an array, a callable or a property path.

$builder->add('plan', ChoiceType::class, [
    'choices' => $plans,
    'choice_label' => 'name',
    'choice_help' => 'description',
    'expanded' => true,
]);

Each help text is rendered under its button and linked to it by aria-describedby: a screen reader reads it with the choice, not at the end of the group. It is translated with choice_translation_domain. A <select> doesn't display it.

And sort_choices

The same version adds sort_choices, which sorts the choices by translated label, following the language's rules (“Égypte” before “Espagne” in French). It needs the intl extension, missing from this sandbox: we don't use it here.

Your task

The subscription form glues each plan's description to its label: the labels become sentences, and nothing ties the explanation to the button.

  1. Keep only the name in the label, and give the description as each choice's help text.

Where the feature comes from: the original pull request.