1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
->add('constructeur_choice', 'choice', array(
'choices' => array(
'01' => '01',
'02' => '02',
'autre' => 'autre'
),
'required' => true,
'mapped' => false,
'label' => 'Constructeur'
)
)
->add('precisez', 'text', array(
"mapped" => false,
"required" => false)
)
->add('constructeur', 'hidden', array(
"required" => false)
)
//...
$builder->addEventListener(
FormEvents::PRE_BIND,
function(FormEvent $event){
$data = $event->getData();
if ( $data['constructeur_choice'] == 'autre'){
$data['constructeur'] = $data['precisez'];
}
else{
$data['constructeur'] = $data['constructeur_choice'];
}
$event->setData($data);
}
); |
Partager