I'm trying to have list of cities based on the region and also the birth date of a person. That is why in my code I tried to do this :
$builder->get('region')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) use ($formModifier) {
$data = $event->getForm()->getData();
$birthDate = $event->getForm()->getParent()->getData();
//formModifier where I am adding the $form->add('city'...
$formModifier($event->getForm()->getParent(), $data, $birthDate);
}
);
However the data I get from $event->getForm()->getParent()->getData() doesn't render the data that I want, it gets the value of the preset data instead of the submitted one.
When I do a dump of $event->getForm()->getParent() I can see that the data that I want to target is in children and that the data that it is currently sending me when I add getData() is in model data.
Symfony\Component\Form\Form {#2290 ▼
-config: Symfony\Component\Form\FormBuilder {#2330 ▶}
-parent: null
-children: Symfony\Component\Form\Util\OrderedHashMap {#2329 ▶}
-errors: []
-submitted: false
-clickedButton: null
-modelData: array:2 [▶]
-normData: array:2 [▶]
-viewData: array:2 [▶]
-extraData: []
-transformationFailure: null
-defaultDataSet: true
-lockSetData: false
-name: "information_salarie"
-inheritData: false
-propertyPath: null
}
I tried to use getChildren() but it says that it doesn't know the method. How can I access the data inside the children element ?
The birth date is in a DateTime input just before the region one. I need it so that I can get the name of the cities at the period the person was born if it's different from the current name.
Thanks a lot for your help !