1. 程式人生 > >symfony CollectionType類型字段子表單字段移除

symfony CollectionType類型字段子表單字段移除

status inter interface list each lse array builder 我們

工作中我們經常會遇到子表單字段移除工作,哪怎麽移除提不想要的子表單字段呢。代碼如下

 1     public function buildForm(FormBuilderInterface $builder, array $options)
 2     {
 3         $builder
 4             ->add(‘stocks‘, CollectionType::class, [
 5                 ‘label‘         => false,
 6                 ‘entry_type‘    => ProductStockType::class
, 7 ‘entry_options‘ => [ 8 ‘label‘ => false, 9 ], 10 ‘allow_delete‘ => true, 11 ]) 12 ; 13 14 $builder->get(‘stocks‘)->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event
){ 15 foreach ($event->getForm()->all() as $f) 16 $f->remove(‘status‘); 17 }); 18 }

symfony CollectionType類型字段子表單字段移除