Skip to content

Commit 2fc27e9

Browse files
authored
Add array example on ChoiceType choice_attr option
1 parent acac494 commit 2fc27e9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

reference/forms/types/options/choice_attr.rst.inc

+18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ If an array, the keys of the ``choices`` array must be used as keys::
1313
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
1414
// ...
1515

16+
$builder->add('attending', ChoiceType::class, [
17+
'choices' => [
18+
1 => Apple,
19+
2 => Banana,
20+
3 => Durian,
21+
],
22+
'choice_attr' => [
23+
1 => ['data-color' => 'Red'],
24+
2 => ['data-color' => 'Yellow'],
25+
3 => ['data-color' => 'Green'],
26+
],
27+
]);
28+
29+
Example for a callable::
30+
31+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
32+
// ...
33+
1634
$builder->add('attending', ChoiceType::class, [
1735
'choices' => [
1836
'Yes' => true,

0 commit comments

Comments
 (0)