-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Reordering in Collections FormType while using AJAX for saving #15526
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
How exactly does the HTML of the items look like before and after changing it via jquery? |
Here is an example of the situation. For simplicity, it is the list of users participating in a meeting:
Second entry after adding via JQuery:
after switching using JQuery, only order in html has changed, but not the IDs: After AJAX-saving, nothing changes in the GUI, but only in the database:
When switching again (without reloading the page), only order in HTML changes:
After reloading the page: I made a little experiment: after switching with jquery and saving via AJAX, I manually switched the IDs and names of the items as well (in firefox's "Q-mode"). This resolved the problem. --> to me it seams that the problem lies in the fact that after first switching and AJAX-saving the IDs of the elements in the GUI do not correspond anymore to the IDs they would get if the form would be built by symfony's form builder. |
Same issue for me.
I add a new item with ajax call. it return a new id (124). And add new item correctly in the "DOM collection".
|
I found a little workaround. I work with Symfony 2.7.4 & Doctrine |
closing as a duplicate of #4492 |
My problem might be related to #4492, however now appeared in Symfony v2.7.3:
Reordering of form collections using AJAX submits does not work correcly.
I have an entity "Meeting", which consists of a collection of "Topics". When reordering the topics, the integer field "position" is re-assigned using javascript based on the current ordering.
When starting, the collection of topics is as follows:
topic[0] : topic ZERO, position 0
topic[1] : topic ONE, position 1
Now I switch the order (using jQuery), it looks as follows:
topic[1] : topic ONE, position 0
topic[0] : topic ZERO, position 1
Now I save this state to the database using AJAX, meaning that in the browser (DOM) nothing changes.
Now I switch the order again, it looks exactly as in the beginning:
topic[0] : topic ZERO, position 0
topic[1] : topic ONE, position 1
Now I save again using AJAX (no visible change in the browser).
When I reload the page, however, something strange appears:
topic[1] : topic ZERO, position 0
topic[0] : topic ONE, position 1
-> The order of topics is not switched but only their content reassigned to the new position, which leads to the situation that the topic's content is changed which should definitely not happen.
-> If I reload after the first saving (meaning standard POST submit with page reload instead of AJAX), everything is fine in the end.
What's wrong here?
Thanks a lot!
The text was updated successfully, but these errors were encountered: