Ask A Question

Notifications

You’re not receiving notifications from this thread.

Auto-removing notices from a turbo_stream

RJ McCollam asked in Rails

I am appending a notice partial via turbo_stream on a few actions for a model. I am running into an issue on figuring out the best way to remove these notices after a set period of time.

The actual javascript on doing it is fine, but with the content being added via a turbo_stream I am not sure how to watch for that.

I have tried wrapping the notice partial with a data-controller to load a stimulus controller, but that doesn't fire when this partial is added.

I also tried listening for turbo events like load, but that isn't triggered either when this partial gets added.

What can I listen to, if anything, to run JS after a turbo_steam even has taken place?

Reply

Do you mean like a flash notice? you can do it as a

function myFunction() {
  setTimeout(function(){ alert("Hello"); }, 3000);
}
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,149+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.