【问题标题】:Symfony4 Element legend not allowed as child of element div in this context在这种情况下,Symfony4 元素图例不允许作为元素 div 的子元素
【发布时间】:2019-03-06 12:29:04
【问题描述】:

Symfony 正在生成 W3C 错误,我不知道如何解决它: 在这种情况下,元素图例不允许作为元素 div 的子元素

这是 HTML 行: <div class="form-group row"><legend class="col-form-label col-sm-2 col-form-label required">Date de naissance</legend><div class="col-sm-10"><div id="lessee_birthday" class="form-inline"><div class="sr-only"> 我认为它是由 formType 生成的

$builder
        ->add('civility', ChoiceType::class, [
            'label' => 'Civilite',
            'choices' => [
                'Mr' => 'Mr',
                'Mme' => 'Mme',
                'Mlle' => 'Mlle',
            ]
        ])
        ->add('name', TextType::class, ['label' => 'Prénom'])
        ->add('lastname', TextType::class, ['label' => 'Nom'])
        ->add('birthday', BirthdayType::class, ['label' => 'Date de naissance']) //here is the problem
        ->add('placeOfBirth', TextType::class, ['label' => 'Lieu de naissance'])
        ->add('email', EmailType::class, ['label' => 'Adresse email'])
        ->add('phoneNumber', TelType::class, ['label' => 'Numéro de telephone'])
    ;

【问题讨论】:

    标签: html css symfony symfony4 w3c-validation


    【解决方案1】:

    根据specification <legend> 标签直接属于<fieldset> 标签之下。您不能将它们与<div> 标签混合使用。

    因此,您必须在模板中更改 BirthdayType 字段的呈现方式。看看 Symfony 中的How to Customize Form Rendering

    【讨论】:

    • 是的,我知道,我一遍又一遍地检查这个文档,但我没有找到解决方案,我尝试了不同的方法,但不是好的方法
    • 如何呈现表单?可以发一下模板吗?您是否尝试按照here 的描述覆盖该字段的模板,例如喜欢{% block birthday_widget %} ...?
    猜你喜欢
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 2013-12-08
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多