Skip to content

Latest commit

 

History

History
104 lines (80 loc) · 2.85 KB

File metadata and controls

104 lines (80 loc) · 2.85 KB

Form Collections

Since collections often tend to make probs, we added some code to ease the use:

And for Subforms:

Make especially sure that your subforms have these options set:

    'widget_form_group_attr' => false,
    'horizontal_input_wrapper' => false,

Otherwise you will have unexpected repeating forms ...

Make sure you included the mopabootstrap-collection.js to have the javascript code loaded and available

Add and Remove Buttons

To make use of the button icons you can either apply them in the FormType:

$builder
    ->add('nice_email_collection','collection', array(
        'widget_add_btn' => array(
            'icon' => 'plus-sign',
            'label' => 'add email'
         ),
    ))
    ;

Or configure them globally:

mopa_bootstrap:
    form:
        collection:
            widget_remove_btn:
                icon: trash
                icon_inverted: true
            widget_add_btn:
                icon: plus-sign

And if configured globally you can override them again in the FormType!

Have a look into the Sandbox to see more examples:

Some things are currently missing :

  • examples on howto extend the functionality with check functions for adding and removing
  • in depth example on howto use Custom FormTypes easily

Nested collections

MopaBootstrapBundle supports nested collections. You can use them as shown below.

At first you need to create a child Form Type with some collection

class MyChildType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('mySubCollection', 'collection', [
                    'type' => 'text',
                ])
        ;
    }
}

After it you need to create a parent Form Type which will use your child form type as a type of collection items.

class MyParentType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('myCollection', 'collection', [
                    'type' => new MyChildType(),
                ])
        ;
    }
}

That's it.


<< Form Extensions | Form Tabs >>