A partial added dynamically can have a valid identifications by using AJAX#468
A partial added dynamically can have a valid identifications by using AJAX#468vtamara wants to merge 8 commits intonathanvda:masterfrom
Conversation
|
Let me see if I understand this correctly: when clicking the Some thoughts:
The actual use of cocoon is to build a form on the client side and submit the complete form for approval. Personally in a lot of my projects I do not use cocoon, but some watered down version that allows to add nested items and immediately saves then (without submitting a complete form), just add/remove nested items. But that is not what this is doing, afaik. So I am bit confused why you would want this. |
Correct.
The method that answer the AJAX request (usually new) has to create new objects with
A record is created every time the user clicks the link (it is a different interaction for the user, but on the positive side it saves more frequently the actions of the user and not only at the end when the user submits).
To offer more interactivity and usability in some forms, not requiring the user to submit the whole form and edit again, but making available some added elements in one region of the form in other regions that depend on them. In the example application if the user adds one objective immediatly it can reference it from the results table (another table in the same form). I hope it is possible to see the enhanced interaction in the video or if you want to try to run the example application. Up to now, the easiest way I have found to give this interactivity to a Rails application is with cocoon and AJAX requests when creating, deleting and updating some elements and redrawing other elements that depend on them.
Yes I understand, I submitted this pull request in case you would like to consider that it is possible to use cocoon+jquery to build more interactive forms. I guess there are more radical approaches possibly Rails+ember or Rails+react. However for some simple cases and many projects already built with rails+jquery+cocoon I guess some interactivity could be added with AJAX and updating the right elements under the right events with jquery.
I like that. However for the scenario I'm using (that other element of the same form have available the just added item), I think once you save the nested item, you would need to update the added element in the view to use the actual identification (instead of the random one), and then update the other regions of the form that could require the added element. I wonder if that approach would make simpler the demo application https://github.com/vtamara/cocoon-ajax-project-objective-result-indicator |
This is a feature that I'm using in several projects.
Besides the documentation included in this pull request,
I prepared a small application that shows how to use it
https://github.com/vtamara/cocoon-ajax-project-objective-result-indicator
and a video of the applicattion running
https://www.youtube.com/watch?v=R5lNVBVOrjU