I have an index page containing a form for creating new things and a list of things that have been created today. Also, below the form, I show details of the most recently created thing.
When the form is submitted, it creates the new thing and redirects back to the index page, where Turbo morphs it. This all works perfectly. There are no turbo frames or stream actions, just morphing.
I now want to paginate the list of things, such that it shows the 20 most recently created along with a “load earlier” button/link. Clicking “load earlier” should retrieve the next 20 things and append them to the list. (If that’s not possible, as a workaround it could retrieve the latest 40 things and let Turbo morph them into the list.)
Ideally when the user creates a new thing, it will be morphed into the top of the list while the list retains all the things it’s got so far (i.e. from the initial page load combined with any load-earlier pagination).
However I can’t figure out how to do it.
Retrieving the next 20 things and appending them to a list in the UI sounds like it needs either a turbo frame or a turbo stream.
If I use a stream response, it prevents morphing from working. If instead I use a frame, it doesn’t seem to do anything.
There’s a section in the handbook on morphing Turbo frames that sounds promising – it mentions pagination – but I don’t understand it:
You can use turbo frames to define regions in your screen that will get reloaded using morphing when a page refresh happens.
…
With this mechanism, you can load additional content that didn’t arrive in the initial page load (e.g., pagination). When a page refresh happens, Turbo won’t remove the frame contents; instead, it will reload the turbo frame and render its contents with morphing.
Any help would be much appreciated!
– Andrew Stewart