Change form field options on checkbox value changing - Symfony 5.1

Viewed 253

I want to disable/enable a group of fields from my form according to a checkbox's state. I dont know how to create the FormEvent, the symfony doc only gives examples for PRE_SET_DATA... This is what i have right now, i know the PRE_SET_DATA event is not what i need to make it work, thank you for your help.

$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
   $form = $event->getForm();
   $utilisateur = $event->getData();
   $checked = $form->get('horaire')->getData();
   if ($checked) {
      $form->get('heure_matin')->setAttribute('disabled', false);
   }
});
1 Answers

I did it with javascript and abandoned the addEventListener idea, maybe it was just technically not possible.

Related