Can I replace a button_to to a controller with a stimulus action while maintaining the default turbo_stream functionality?

I have a simple list where each item has a button to create a new item, this turbo_streams the new item to a list. (think of adding items to an always shown shopping cart)

(rails-7 app)

this works perfectly,

however, the client requested to be able to add the items via a double-click action. I added the double-click via stimulus, but when the create is performed via stimulus it no longer turbo-streams (since it’s now an Ajax call)

what would be the “best” way to achieve this?,

  • can I visually hide the button, and have stimulus “click” it?
  • can I stream triggered via Ajax?
  • do I need to create a stream and subscribe to it?

Can you say more about the original button, and how it was set up? Is it an actual form button element, or is it a link, styled as a button? Does it send a POST to an items collection route to create a new item?

What is the native behavior of your application before you changed it?

Then, what’s in your Stimulus controller? Does it simply trap the single click and wait for the second click of a double-click?

I think the larger answer to your questions are “you can do pretty much anything”. There may be a way to leverage what the defaults are, so you only have to change one thing to get the desired behavior, but without a better idea of your context, it’s hard to know precisely what to suggest.

Walter