I am building a checkbox form that has 4 possible choices. What would be the method of making 2 and 3 (Green and Blue) checked by default but leaving the remaining two items unchecked by default?
I believe the "data" item of the $builder array might be the correct answer, but I am not sure how... Any help would be appreciated! Thank you!
$builder->add(
"What color do you like?",
ChoiceType::class,
[
'label' => "What color do you like?",
'choices' => [1 => "Red", 2 => "Green", 3 => "Blue", 4=>"Orange"],
'expanded' => true,
'multiple' => true,
'required' => true,
'help' => "Pick as many as you like!",
]
);
I expect that I should be able to code in something like "2=1,3=1" somewhere to indicate that both of my choices should be checked by default, but it is not clear how I would indicate that those two choices should be checked by default.
Aucun commentaire:
Enregistrer un commentaire