duanlou2917 2019-05-15 09:40
浏览 127

Symfony 3 - 向FormType添加样式(Entity :: class => choiceLabels)

I have a formType that contains an EntityType :: class. This is a list of possible types of users to choose from in a form.

->add('typeUser',EntityType::class, array(
            'required' => true,
            'class'=>'Site\PagesBundle\Entity\TypeUser',
            'choice_label'=>'typeUtilisateur',
            'expanded'=>true,
            'multiple'=>true,
            'empty_data' => 'Veuillez sélectionner au moins 1 type',
        ));

I wish I could give a "style" to these choices. For example, I would like them to be some distance from the checkbox.

So, I have to add style (margin-left by example) to :

'choice_label'=>'typeUtilisateur',

Is it possible in FormType ?

Or I should make that on my twig file ? In this case, how can I do it ?

Thanks for your help !

EDIT:

->add('typeUser',EntityType::class, array(
            'required' => true,
            'class'=>'Site\PagesBundle\Entity\TypeUser',
            'choice_label'=>('typeUtilisateur' => 'attr' => array( 'style' => 'margin-left:15px')) ,
            'expanded'=>true,
            'multiple'=>true,
            'empty_data' => 'Veuillez sélectionner au moins 1 type',
        ));
  • 写回答

2条回答 默认 最新

  • douwen7516 2019-05-15 09:54
    关注

    There are a few ways you can style your form fields. See a few of them below:

    Option 1: Add a class attribute to the field in the form builder

    $builder
        ->add('example', EntityType::class, [
            'class' => FooBar::class,
            'attr' => [
                 'class' => 'my-example-class'
            ]
        ])
    

    Option 2: Specify a class in the form template

    {{ form_widget(form.fooBar, {'attr': {'class': 'form-control'}}) }}
    

    You can be specific to the choices, see this link here which shows adding a class attribute to choices.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器