0

我试图在 Symfony 4.4 中显示重复密码字段的错误消息。

这是表单类文件中的相关代码:

->add('password', RepeatedType::class, array(
            'required' => true,
            'invalid_message' => 'Le mot de passe et sa confirmation ne sont pas identiques',
            'type' => PasswordType::class,
            'first_options' => array('label' => false,'error_bubbling' => true),
            'second_options' => array('label' => false),
        ))

这是我的相关树枝/HTML代码:

<div class="col-md-4 mb-4">
                                    <div class="form-outline">
                                        {{ form_row(registrationForm.password.first ,{'label':false,'attr':{'placeholder':'Mot de passe', 'name':'password1', 'class':'form-control', 'id':'password1'} } ) }}
                                        <span style="color: red">{{ form_errors(registrationForm.password|first) }}</span>
                                    </div>
                                </div>

实际上,如果我更改form_errors(registrationForm.password|first)form_errors(registrationForm.password),我会得到:

在此处输入图像描述

但是,这不是想要的结果,因为我只需要显示一个简单的文本,我真的很想知道为什么form_errors(registrationForm.password|first)不适合我。任何想法?

4

1 回答 1

0

我已经修好了!我实际上采用了不同的方法。在我的 HTML\Twig 代码中,我将这一行更改为<span style="color: red">{{ form_errors(registrationForm.password|first) }}</span>

<span class="Errormessage" style="color: red;text-align: right">{{ form_errors(registrationForm.password) }}</span>

然后,我在我的 CSS 代码中添加了以下代码:

.Errormessage li {
    list-style-type: none !important;
}
于 2022-01-06T10:24:10.983 回答