Closed JeremyDulon closed 4 years ago
After some diggging, I have been able to access the id value of the User through the form.vars.data value, where I test if the data is empty and if not get the id.
If you guys have a more proper way to do so I'm listening
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Environment
Windows 10, WampServer
Sonata packages
Symfony packages
PHP version
5.6.25
Subject
On an admin class WatchText, I got a relationship One to Many relationship WatchTextUsers, with the type "sonata_type_collection". In this embedded form, I got three fields, a User (where I use the "sonata_type_model_autocomplete" type), and two text fields.
Steps to reproduce
When you create a WatchText entity, you can add as many User as you want, and filling the following two fields according.
So this works quite well, you can then save all your entity, and in the database the User is linked with the WatchTextUser.
But, when you edit an existing WatchText, even though you can see the existing WatchTextUsers, with the three fields filled (even the autocomplete, with the property of my User entity), I am not able to save my form correctly.
Expected results
When I save the form, only the two texts fields are maintained, the WatchTextUser I've added on the current edit only. Which means I lost every previously existing relation between WatchTextUser and User.
Actual results
I've been digging up a bit to see what's changing between both methods (displaying an existing autocomplete input and creating then selecting one), and I've discovered that the div with id ending with _hidden_inputs_wrap is supposed to hold the id of the linked entity in the value attribute.
When you make a change on the autcomplete field, the event on 'change' triggers, and append the hidden input with the id as value. But on the loading, the div _hidden_inputs_wrap is supposed to have the id set in the value attribute, but is empty instead. And the value twig variable which is supposed to contain the id data is and empty array in my case..