MopaBootstrapBundle icon indicating copy to clipboard operation
MopaBootstrapBundle copied to clipboard

Missing documentation in nested collections

Open aferrandini opened this issue 11 years ago • 5 comments

In reference to issue #858 there is a missing documentation for nested collections. The problem is not in the Javascript as is mention in the issue #858. There is a configuration problem.

When you have nested collections you have to set the attr data-widget-controls to "true"

This will change the itemSelector in the Javascript and then will use div.collection-id. > .collection-items > .collection-item instead of div.collection-id. > .collection-item

So an example of the FormType will be something like this:

<?php
//Collection1Type.php
...
class Collection1Type extends AbstractType
{
    public function buildForm (FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('field_name', 'collection', array(
                'type' => new Collection2Type(),
                'allow_add' => true,
                'allow_delete' => true,
                'prototype_name' => '__collection1block__',
                'attr' => array(
                    'data-widget-controls' => 'true'
                )
            ))      
    }
    ....
}
<?php
//Collection2Type.php
...
class Collection2Type extends AbstractType
{
    public function buildForm (FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('field_name', 'collection', array(
                'type' => new Collection3Type(),
                'allow_add' => true,
                'allow_delete' => true,
                'prototype_name' => '__collection3__',
                'attr' => array(
                    'data-widget-controls' => 'true'
                )
            ))      
    }
    ....
}
<?php
//Collection3Type.php
...
class Collection3Type extends AbstractType
{
    public function buildForm (FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name')      
            ->add('email', 'email')      
    }
    ....
}

aferrandini avatar Nov 20 '14 08:11 aferrandini

@aferrandini Can you please create that doc as a PR?

phiamo avatar Jan 12 '15 10:01 phiamo

Sure, let me have some free time to do that :)

aferrandini avatar Jan 12 '15 11:01 aferrandini

ping @aferrandini :-)

phiamo avatar May 30 '15 09:05 phiamo

Sorry I had not time to do it, I'll try to work on that this week.

aferrandini avatar Jun 11 '15 12:06 aferrandini

That would be great, thanks

phiamo avatar Jun 11 '15 12:06 phiamo