8000 fix form collection label not correct · stoccc/symfony-docs@dfa3891 · GitHub
[go: up one dir, main page]

Skip to content

Commit dfa3891

Browse files
authored
fix form collection label not correct
Fixes this symfony#6607 in 2.7 branch
1 parent 21aba6b commit dfa3891

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

form/form_collections.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ Notice that you embed a collection of ``TagType`` forms using the
133133
{
134134
$builder->add('description');
135135

136-
$builder->add('tags', 'collection', array('type' => new TagType()));
136+
$builder->add('tags', 'collection', array(
137+
'type' => new TagType(),
138+
'options' => array('label' => false)
139+
));
137140
}
138141

139142
public function configureOptions(OptionsResolver $resolver)
@@ -290,9 +293,10 @@ add the ``allow_add`` option to your collection field::
290293
public function buildForm(FormBuilderInterface $builder, array $options)
291294
{
292295
$builder->add('description');
293-
296+
294297
$builder->add('tags', 'collection', array(
295298
'type' => new TagType(),
299+
'options' => array('label' => false),
296300
'allow_add' => true,
297301
));
298302
}
@@ -399,9 +403,15 @@ one example:
399403
// get the new index
400404
var index = $collectionHolder.data('index');
401405
406+
var newForm = prototype;
407+
// You need this only if you didn't set 'label' => false in your tags field in TaskType
408+
// Replace '__name__label__' in the prototype's HTML to
409+
// instead be a number based on how many items we have
410+
// newForm = newForm.replace(/__name__label__/g, index);
411+
402412
// Replace '__name__' in the prototype's HTML to
403413
// instead be a number based on how many items we have
404-
var newForm = prototype.replace(/__name__/g, index);
414+
newForm = newForm.replace(/__name__/g, index);
405415
406416
// increase the index with one for the next item
407417
$collectionHolder.data('index', index + 1);

0 commit comments

Comments
 (0)
0