【问题标题】:Remove 'label__' from prototype name从原型名称中删除 'label__'
【发布时间】:2015-01-14 10:51:43
【问题描述】:

我有这样的表格:

$formMapper
    ->add('formats', 'collection', array(
        'type'         => new FormatType(),
        'allow_add'    => true,
        'allow_delete' => true,
        'prototype' => true,
        'prototype_name' => 'remove'
    ))
    ->add('papers', 'collection', array(
        'type'         => new PaperType(),
        'allow_add'    => true,
        'allow_delete' => true,
        'prototype' => true,
        'prototype_name' => 'remove'
    ))
;

如您所见,我将prototype_name 更改为remove

原来是这样的:

当我点击加号时,我得到这个:

如您所见,添加了 remove 文本。而且还有 label__* 。如何解决标签__* 文本未添加或显示的问题?

【问题讨论】:

  • 你为什么使用prototype_name选项?
  • 我正在尝试更改标签..
  • prototype-name 似乎不是正确的选择。你试过使用label => ''吗?
  • 然后我得到 name__label 而不是 removelabel_
  • 如何显示表单?

标签: forms symfony symfony-forms


【解决方案1】:

使用'label_attr' => ['style' => 'display: none']

$formMapper
    ->add('formats', 'collection', array(
        'type'         => new FormatType(),
        'allow_add'    => true,
        'allow_delete' => true,
        'prototype' => true,
        'label_attr' => ['style' => 'display: none']
    ))
    ->add('papers', 'collection', array(
        'type'         => new PaperType(),
        'allow_add'    => true,
        'allow_delete' => true,
        'prototype' => true,
        'label_attr' => ['style' => 'display: none']
    ))
;    

【讨论】:

    【解决方案2】:
    ->add('appointment', CollectionType::class,[
                'label' => false,
                'entry_type' => AppointmentType::class,
                'entry_options' => ['label' => false],
                'allow_add' => true,
                'allow_delete' => false,
                'prototype' => true,
            ])
    

    这是我添加约会的集合,请参阅 entry_options

    【讨论】:

      猜你喜欢
      • 2013-02-16
      • 1970-01-01
      • 2014-04-10
      • 2021-11-07
      • 1970-01-01
      • 2015-04-18
      • 2013-01-15
      • 2010-11-06
      • 1970-01-01
      相关资源
      最近更新 更多