【问题标题】:How to get only text instead of list item from form_errors如何从 form_errors 只获取文本而不是列表项
【发布时间】:2021-12-31 16:36:02
【问题描述】:

我正在尝试在 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) 不适合我。有什么想法吗?

【问题讨论】:

    标签: forms text twig message symfony-4.4


    【解决方案1】:

    我已经解决了!我实际上采用了不同的方法。在我的 HTML\Twig 代码中,我更改了这一行 &lt;span style="color: red"&gt;{{ form_errors(registrationForm.password|first) }}&lt;/span&gt;,如下所示:

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

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

    .Errormessage li {
        list-style-type: none !important;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      • 2011-08-18
      • 1970-01-01
      相关资源
      最近更新 更多