T
T
Tarakkolya2014-07-25 09:38:13
symfony
Tarakkolya, 2014-07-25 09:38:13

How to remove empty fields from bootstrap collection?

Can you please tell me how to delete empty fields when using bootstrap collection? The delete empty option is enabled.

class HostType extends BaseType
{
    public function buildForm(FormBuilderInterface $builder,array $options)
    {
        $builder->add('username','text',array('label'=>'Name'))
                ->add('email','text')
                ->add('about',null,array('label'=>'About host'))
                ->add('picture','iphp_file')
                ->add('videos','bootstrap_collection',array(
                                'type'=>new HostVideoType(),
                                'allow_add'=>true,
                                'allow_delete'=>true,
                                'cascade_validation' => true,
                                'delete_empty'=>true,
                                'add_button_text'    => 'Add video to host',
                                'delete_button_text' => 'Delete video from host',
                ));
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
           'data_class' => 'iCliqueLive\HostBundle\Entity\Host',
           'validation_groups' => array('addHost'),
           'cascade_validation'=>true,
        ));
    }

    public function getName()
    {
        return 'host';
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Gusakov, 2014-07-26
@Tarakkolya

Set by_reference to false and write methods addVideo, removeVideo instead of setVideos

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question