-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Dynamic Form - Multiple field dependant #11902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@raziel057 thanks for opening this issue and for suggesting us how to improve Symfony. I'm afraid that this is a feature that lots of Symfony developers have requested before. Two years ago this issue was opened to discuss about this: Support dependent fields. And one year ago this other related issue was opened: Harden the form lifecycle to improve support for dynamic forms. My guess is that we won't see this feature added to the forms anytime soon. My suggestion to you would be to use a third-party bundle such as ShtumiUsefulBundle that supports this feature or to use some frontend technology to solve this part of the application (maybe AngularJS). |
@javiereguiluz Thanks for your comment and the different links.
|
You would have to attach your listener on the parent instead of trying to access the data of the parent form ( |
and you should set your form on |
@stof I already tried to attach a listener $roomType = $event->getForm()->get('roomType')->getData(); // <- null
$startTime = $event->getForm()->get('startTime')->getData(); // <- null
$endTime = $event->getForm()->get('endTime')->getData(); // <- null I also tried to attach a listener |
From my understanding events are triggered like this: ROOT FORM - PRE_SUBMIT |
this is because in and yes, your understanding of the order of events is right. And this is exactly why replacing a child on |
Ok so I will use the raw data in the PRE_SUBMIT event. I thougth about that. It's not an ideal solution because I need to create objects from the array structrure (datetime for example) but it can be a solution I think. I just wanted to know if it could be a better solution but apparently not. It's not very problematic but if there is a rework of the Form component for Symfony 3 it can be considered. Thank you very much for your reply! |
It seems that the issue reporter (@raziel057) received a satisfactory solution, so we could close this issue. |
@raziel057 You may create a class for your listener, and listen on multiple events, and save some stuff in class properties, to use them in other events. Have a look at this CollectionUploadSubscriber.
Ofcourse your needs are diffrent, but I think this example shows some things you might now have been aware of. And as @stof suggested - you should listen on root form to have access to all fields. |
I'm closing this as a duplicate of #5807. |
Hi,
Currently it's possible to create and populate fields based on an other one by using Listeners as in sample http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html#dynamic-generation-for-submitted-forms
But I seems to be not possible to make the field depend on multiple fields. For example, I would like to populate a list of available rooms depending on the type of room, start date and end date.
I tried by adding the following listener:
As you can see
$startDate
and$endDate
are null at this time (not yet bound in the root form, I think). So I also tried to create aPOST_SUBMIT
listener attached to the root form but I have an error because I can't create new field onPOST_SUBMIT
at root form level.If I replace the listener on
roomType
by a listener withSUBMIT
EVENT at root level, I get always null inhallConfiguration
(because the field was bound before).It would be interesting to be able to support dynamic form with multiple dependent fields as in my sample.
@webmozart Any ideas on this possible feature ?
The text was updated successfully, but these errors were encountered: