Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony form builder update option field

is it possible to update an option field after adding it ?

$builder
    ->add('examens', 'entity', array(
        'class' => 'TelegrammeExamenBundle:ExamExamen',
        'property'  => 'libelle',
        'required'    => true,
        'empty_value' => 'Sélectionnez un examen',
        //'data' => $this->em->getReference("TelegrammeExamenBundle:ExamExamen", 510),
        'data' => null,
        'query_builder' => function(ExamenRepository $r) {
            return $r->getSelectList();
        },
        'attr' => array('class' => 'bg_white_filet_gris')
    ))
;

how modify field option ??? (setOption don't exist)

if (...) $builder->get('examens')->setOption('property', 'test');
like image 800
stloc Avatar asked Jun 13 '14 10:06

stloc


1 Answers

You can simply ->add() it again. As the API documentation suggests for the add method: Adds or replaces a child to the form

http://api.symfony.com/2.8/Symfony/Component/Form/FormInterface.html#method_add

This can be used to modify form elements for example in a FormEvent.


Alternatively the FormBuilder provides a setAttribute() method which can be used as follows:

$builder->get('examens')->setAttribute('property', 'test');
like image 193
Debreczeni András Avatar answered Nov 02 '22 13:11

Debreczeni András