Stimulus data-actions and turbo events

In a recent tweet by Kasper, he showed an example I hadn’t considered before in using data-action="turbo:load->search#closeResults".

Reacting to turbo events in data-actions is a very flexible approach.

I tried a firing an action on turbo:load using data-action, but the action did not fire. In order to get it to work, I had to add @window.

- data-action="turbo:load->my-controller#doSomething"
+ data-action="turbo:load@window->my-controller#doSomething"

Any ideas as to why I can’t get it to work similar to the example from Kasper?

1 Like

Looks like Kasper also added the @windows:

Here’s the code straight from HEY:

There are @windows and @documents on his <div id="search_container">.

My guess is these were stripped out of the tweet because he’d’ve run out of characters :joy:

Hah! I didn’t even think to look at the actual deployed code. Nice catch!