-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
Description
Hi,
i tried to remove an element dynamicaly from my form (as suggested possible in http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html : Example: you have a "Product" form and need to modify/add/remove a field based on the data on the underlying Product being edited.)
The form type:
$builder->add('object');
$builder->add('message');
$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) {
$form = $event->getForm();
$form->remove('object');
});
Depending on how the form is created, the behavior is different:
$formFactory->create($formType, $data, $options) // LISTENER IS CALLED BUT ELEMENT NOT REMOVED
$form = $formFactory->create($formType, null, $options)
$form->setData($data) // LISTENER IS CALLED AND ELEMENT IS REMOVED
I am using symfony 2.2
Thank you for feedback
Tom