猿问

如何设置 repeatedType 字段表单的样式?

从 symfony 5,我有一个包含表单的视图(用于创建新用户)。在此表单中,我为密码添加了一个 RepeatedType 字段。

一切正常。

现在我想添加一些样式,但我遇到了困难:

通过 Symfony API,我找到了如何将 css 类添加到 div“#user_password”(图中的黑框),我找到了如何将 css 类添加到输入(图中的绿框)。但是我找不到如何将类添加到图像中蓝色框中的div。我正在寻找一种将类“col-6”添加到“blue div”的方法


我的代码:


        ->add('password', RepeatedType::class, [

            'type' => PasswordType::class,

            'label' => false,

            'first_options'  => [

                'label' => false,

                'attr' => [

                    'class' => 'form-control trapezoid',

                    'placeholder' => 'Password'

                ]

            ],

            'second_options' => [

                'label' => false,

                'attr' => [

                    'class' => 'form-control trapezoid',

                    'placeholder' => 'Password²'

                ]

            ],

            'attr' => [

                'class' => 'row',

            ],

            'row_attr' => [

                'class' => 'col-6', // has no effect

            ]

        ])

以及我的 twig 文件中用于密码字段的代码:


<div>

    {{ form_widget( form.password) }}

</div>

{{ form_help(   form.password) }}

{{ form_errors( form.password) }}


胡说叔叔
浏览 84回答 1
1回答

月关宝盒

在first_option和second_option中使用 ' row_attr ''first_options'&nbsp; =>&nbsp;[&nbsp; &nbsp; 'label' => false,&nbsp; &nbsp; 'attr' => [&nbsp; &nbsp; &nbsp; &nbsp; 'class' => 'form-control trapezoid',&nbsp; &nbsp; &nbsp; &nbsp; 'placeholder' => 'Password'&nbsp; &nbsp; ],&nbsp; &nbsp; 'row_attr' => [&nbsp; &nbsp; &nbsp; &nbsp; 'class' => 'col-6',&nbsp;&nbsp; &nbsp; ]],
随时随地看视频慕课网APP
我要回答