在 symfony 形式中,我有一些选择,复选框。
$form->add('keywords', ChoiceType::class, array(
'choices' => $keywords,
'label' => 'With following keywords',
'expanded' => true,
'multiple' => true,
));
当表单初始化时,我需要选择所有复选框。 如果可能的话,我该如何以 symfony 方式做到这一点,或者我需要使用 JavaScript 来做到这一点?
最佳答案
只需添加choice_attr
$form->add('keywords', ChoiceType::class, array(
'choices' => $keywords,
'label' => 'With following keywords',
'expanded' => true,
'multiple' => true,
'choice_attr' => function() {
return ['checked' => 'checked'];
},
));
关于php - 选择 Symfony 表单 View 中的所有复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41238413/