From dfa3891b231a678dfe6fd5553eaa1f3bab1868db Mon Sep 17 00:00:00 2001 From: stoccc Date: Fri, 11 Aug 2017 11:40:25 +0200 Subject: [PATCH] fix form collection label not correct Fixes this https://github.com/symfony/symfony-docs/issues/6607 in 2.7 branch --- form/form_collections.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/form/form_collections.rst b/form/form_collections.rst index 2e0426e2fcb..2899303e178 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -133,7 +133,10 @@ Notice that you embed a collection of ``TagType`` forms using the { $builder->add('description'); - $builder->add('tags', 'collection', array('type' => new TagType())); + $builder->add('tags', 'collection', array( + 'type' => new TagType(), + 'options' => array('label' => false) + )); } public function configureOptions(OptionsResolver $resolver) @@ -290,9 +293,10 @@ add the ``allow_add`` option to your collection field:: public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('description'); - + $builder->add('tags', 'collection', array( 'type' => new TagType(), + 'options' => array('label' => false), 'allow_add' => true, )); } @@ -399,9 +403,15 @@ one example: // get the new index var index = $collectionHolder.data('index'); + var newForm = prototype; + // You need this only if you didn't set 'label' => false in your tags field in TaskType + // Replace '__name__label__' in the prototype's HTML to + // instead be a number based on how many items we have + // newForm = newForm.replace(/__name__label__/g, index); + // Replace '__name__' in the prototype's HTML to // instead be a number based on how many items we have - var newForm = prototype.replace(/__name__/g, index); + newForm = newForm.replace(/__name__/g, index); // increase the index with one for the next item $collectionHolder.data('index', index + 1);