Skip to content

Commit 9176faa

Browse files
LucileDTwouterj
authored andcommitted
Add array example on ChoiceType choice_attr option
1 parent acac494 commit 9176faa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ 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('fruits', ChoiceType::class, [
17+
'choices' => [
18+
'Apple' => 1,
19+
'Banana' => 2,
20+
'Durian' => 3,
21+
],
22+
'choice_attr' => [
23+
'Apple' => ['data-color' => 'Red'],
24+
'Banana' => ['data-color' => 'Yellow'],
25+
'Durian' => ['data-color' => 'Green'],
26+
],
27+
]);
28+
29+
// or use a callable
1630
$builder->add('attending', ChoiceType::class, [
1731
'choices' => [
1832
'Yes' => true,

0 commit comments

Comments
 (0)