How to render a checkbox that is checked by default with the symfony2 Form Builder?

后端 未结 13 2247
鱼传尺愫
鱼传尺愫 2020-12-17 09:30

I have not found any easy way to accomplish to simply check a Checkbox by default. That can not be that hard, so what am i missing?

13条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 10:28

    To complete a previous answer, with a multiple field you can do that to check all choices :

       'choice_attr' => function ($val, $key, $index) {
           return array('checked' => true);
       }
    

    https://symfony.com/doc/3.3/reference/forms/types/choice.html#choice-attr

提交回复
热议问题