You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a compound form and you call setData() with changed data inside a listener for the FormEvents::SUBMIT the data is not changed correclty. When the handleRequest() function is finished the normdata, viewdata and modeldata of the compound form are correct but the values of the children forms haven't changed. If you call $form->createView() after this the form doesn't contain the changes.
With this code you will see that the normdata, viewdata and modeldata of the complete form featureType is updated and the name is set to 'test' but the child form, the name form that is a TextType, still has an empty value so if you render the form the name field stays empty.
The text was updated successfully, but these errors were encountered:
To sum it up: The data change by using setData does change the data but this changed isn't propagated to the children. So by rendering the form after this the form fields still have the old values.
I already expected that the submit of the children has been handled before. I can't use the first option because I want to change a different field (e.g. 'age') that is on the same level as 'name'. So if I handle a event on name I can't change the data of another field then name, AFAIK.
I will then have to go for the second options. Then I have to resolve some entities myself which would have been resolved automatically if I could use the SUBMIT event.
IMHO it would be very helpful to add a extended workflow with child forms to the Form Events page in the cookbook (http://symfony.com/doc/current/components/form/form_events.html). This would help to undestand when which event on which form (parent or child) gets triggerd.
If you have a compound form and you call
setData()
with changed data inside a listener for theFormEvents::SUBMIT
the data is not changed correclty. When thehandleRequest()
function is finished the normdata, viewdata and modeldata of the compound form are correct but the values of the children forms haven't changed. If you call$form->createView()
after this the form doesn't contain the changes.Example code to reproduce bug:
Controller:
Form:
DTO:
With this code you will see that the normdata, viewdata and modeldata of the complete form featureType is updated and the name is set to 'test' but the child form, the name form that is a TextType, still has an empty value so if you render the form the name field stays empty.
The text was updated successfully, but these errors were encountered: