形成一个集合小部件

mat*_*h88 6 symfony twig

我的表单中有一个集合小部件.这显示如下:

球队0球员
1输入球场1球员2输入球场

我想不显示'团队'这个词,'0'和'1'.我在fields.html.twig模板中有这个块,但不确定如何编辑它.

{% block collection_widget %}
{% spaceless %}
    {% if prototype is defined %}
        {% set attr = attr|merge({'data-prototype': form_row(prototype) }) %}
    {% endif %}
    {{ block('form_widget') }}
{% endspaceless %}
{% endblock collection_widget %}

{% block form_label %}
{% spaceless %}
    <div class="hidden">
        {{ block('generic_label') }}
    </div>
{% endspaceless %}
{% endblock form_label %}
Run Code Online (Sandbox Code Playgroud)

ChallengeType表格:

class ChallengeType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('teams', 'collection', array(
                'type' => new TeamType(),
                'allow_add' => true
            ))
            ->add('place')
            ->add('date');
    }

    public function getName()
    {
        return 'challenge';
    }

    public function getDefaultOptions(array $options)
    {
        return array('data_class' => 'Tennisconnect\DashboardBundle\Entity\Challenge');
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

Mun*_*Das 5

那些标签是在form_label块中创建的.我通常将它们包装在一个div中,并在需要时将它们隐藏起来.

编辑:

有一个更好的解决方案:).

改变collection的部分ChallengeType.php用以下

->add('teams', 'collection', array(
                'type' => new TeamType(),
                //label for Teams text
                'attr' => array('class' => 'team-collection'),
                //label for each team form type
                'options' => array(
                  'attr' => array('class' => 'team-collection')
                ),
                'allow_add' => true
            ))
Run Code Online (Sandbox Code Playgroud)

现在这些不需要的标签将有team-collection类.在你的CSS文件,您可以设置display:nonelabel.team-collection.无需更改表单主题块定义.