I found a few similar topics, but unfortunately no solution at all. Hopefully somebody can help me out.
So I expect, what I want to do is not how drive is designed, but please give me a hint, how to accomplish my situation.
I have a stimulus popup controller (based on Super easy modals with Rails and Stimulus (and a bit of Tailwind)), which loads different kinds of views all over the application.
Each of those loaded views, may be loaded in this popup, but also as the main view of the application, or they may be load in a turbo-frame. It simply depends on the context, in which the user wants to interact with some information.
However, in the most cases, when we open a popup, there’s a form in it, which provides the user the possibility of modifying some data.
Turbo handles the form-submission fine, if there are errors (status code 422), then the form is just replaced in the modal including the error messages. Just like designed.
But if the request was successful, a redirection occurs.
Sure, that’s because the controllers’ default is to respond with the redirection in the response, if the update was successful. This is also a good behaviour for all other contexts, in which those views may be rendered.
But in the case of the modal, the expected behaviour would be, that the model just closes (and raises an event to some subscribers, that it updated some data successfully). But it should NOT redirect the whole page.
I also don’t think, it would be a good solution to send some more http headers from within the popup, and modify each controller, to prevent the redirection for this special “request-from-popup-case”.
I also don’t like the idea of wrapping all of those views in separate turbo-frames, as this might also have side-effects in some other contexts.
Actually I’d expect I should be able to subscribe to the turbo:submit-end event (what’s actually possible).
This is pretty good, as I can read the information, if the submission was successful or not.
Now I can inform several subscribers with a CustomEvent, that the change in the modal was done properly.
But in the end a full redirection appears.
I thought I simply could call event.preventDefault(), but unfortunately it doesn’t prevent turbo from performing the redirection.
What am I missing?
Thanks alot for your help!