I'm trying to get a dynamic form but it never worked. Basicly, what I want is that, when I select the service, id adds a new field named Chambre that is get like $selectedService->getChambres(). But it always says that the Select Service is null Here's the code:
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder = new DynamicFormBuilder($builder);
$builder
->add('dateDebut', DateType::class, array(
'label'=> 'Date début : ',
'label_attr' => ['class' => 'label'],
))
->add('dateFin', DateType::class, array(
'label'=> 'Date début : ',
'label_attr' => ['class' => 'label'],
))
->add('commentaire', TextType::class,array(
'label'=> 'Commentaire : ',
'label_attr' => ['class' => 'label'],
'attr' => ['class' => "input"]
))
->add('isArrive', CheckboxType::class, array(
'label'=> 'Arrivé : ',
'label_attr' => ['class' => 'label'],
'attr' => ['disabled' => 'disabled'],
'data' => false
))
->add('isOut', CheckboxType::class,array(
'label' => 'Départ : ',
'label_attr' => ['class' => 'label'],
'attr' => ['disabled' => 'disabled'],
'data' => false
))
->add('patient',EntityType::class, array(
'label' => 'Patient :',
'label_attr' => ['class' => 'label'],
'class' => Patient::class,
'choice_label'=> 'nomComplet',
'attr' => ['class' => 'select']
))
->add('service', EntityType::class, array(
'class' => Service::class,
'label' => 'Service : ',
'label_attr' => ['class' => 'label servField']
)) //the selected service
->add('Submit',SubmitType::class,array(
'label' => 'Ajouter séjour',
'attr' => ['class' => 'button is-primary']
))
->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event):void{
$event->getForm()->add('lit', ChoiceType::class, [
'choices' => $event->getData()->getService(),
]);
});
}
I've already tried to change PRE_SET_DATA w/ POST_SET_DATA, PRE_SUBMIT, POST_SUBMIT, ... (everything possible). I've also tried some things on these website :