Shape Collection Widget

I have a collection widget in my form. It looks like this:

Teams 0 player1 inputfield
1 player2 inputfield

I would not want to display the word β€œteams” and β€œ0” and β€œ1”. I have this block in my fields.html.twig template, but not quite sure how to change this.

{% 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 %} 

ChallengeType Form:

 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'); } } 

thanks.

+6
source share
1 answer

These tables are created in the form_label block. I usually wrap them in a div and set them if necessary.

Edit:

There is a better solution :).

Change the collection section of ChallengeType.php as follows

 ->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 )) 

Now these unwanted tags will have a team-collection class. In the css file, you can set display:none for label.team-collection . You do not need to change the definition of the form theme block.

+5
source

Source: https://habr.com/ru/post/911033/


All Articles