【问题标题】:Symfony Forms add placeholder to the prototype of collection fieldSymfony Forms 将占位符添加到集合字段的原型中
【发布时间】:2019-03-05 04:50:17
【问题描述】:

我正在寻找一种将占位符添加到集合字段原型的方法。添加属性“占位符”不会产生任何效果。 我尝试使用prototype_data并在twig中用占位符替换值属性,但如果字段类型是数字,则会引发错误,并且传递的文本值不能转换为数字。

$builder->add('fees', CollectionType::class, [
            'allow_add' => true,
            'allow_delete' => true,
            'delete_empty' => true,
            'entry_type' => TextType::class,
            'prototype' => true,
            'attr' => [
                'placeholder' => 'Fee Type',
            ],
        ])

【问题讨论】:

  • attr 选项移动到entry_options

标签: forms symfony collections twig placeholder


【解决方案1】:

通常,您可以通过entry_optionsentry_type 选项(在您的情况下为TextType)中指定的表单类型的任何可用选项嵌入到CollectionType 的所有条目中。

特别是你的问题,你应该使用这个:

$builder->add('fees', CollectionType::class, [
        'allow_add' => true,
        'allow_delete' => true,
        'delete_empty' => true,
        'entry_type' => TextType::class,
        'prototype' => true,
        'entry_options' => [
            'attr' => [
                'placeholder' => 'Fee Type',
            ]
        ]
    ])

文档here

【讨论】:

    猜你喜欢
    • 2019-08-30
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 2020-11-11
    • 2017-10-23
    • 2017-07-13
    • 2014-03-22
    • 1970-01-01
    相关资源
    最近更新 更多