Turbo stream append not working when clicked more than once

Hi guys!

We started using Hotwire in our new project and we’re loving it!

There’s an issue we’re currently having with Turbo, where Turbo Stream append only works at the first click. We have a donation.html page where the user can add fields via Turbo streams.

The donation.html.slim page looks like so:

turbo-frame#donation-rows
        = link_to t("custom"),
          custom_path(report_id: @report.id)
#donation-row_1

donation_field.html.slim:

turbo-stream action="append" target="donation-row_1"
  template
    #donation-row_1
      | fields

After the user clicks on the button, Turbo frame changes and adds a src to it:

turbo-frame#donation-rows src="<URI>"

This prevents that the button can be clicked more often, if the user decides to add more fields. We could of course delete the src it adds with JavaScript but we’d like to refrain from doing so.

Is there something that we’re doing wrong or do we need to apply some changes to the code in order for it to work?

Any suggestions are greatly appreciated!

Have a nice weekend!

Best Regards

Try changing link_to to button_to and see if that makes a difference.

See also: Compatibility with Rails UJS

Hey @alig,

I am curious how you got the src in the turbo frame tag to change once a user presses the button. I am using turbo frame tag: <%= turbo_frame_tag “car_show”, src: “http://localhost:3000/cars/bmw” %> and I have a stimulus controller pulling the URL of a car in the partial that is clicked on. How are you changing the src when a user clicks?

Thank you in advance!

@strobilomyces
Changing it to button_to doesn’t work. Whenever I click on the button, the button disappears and no field gets added.

@automatemystartup
Hi Jurell!

My turbo frame doesn’t have an src initially, only the id=“donation_rows”. Whenever I click on the button, the src gets appended to the turbo frame. When I remove the added src, it works and one more field gets added.

As of right now, I don’t have anything that alters the src. I haven’t used turbo_frame_tag but I’ll definitely have a look at it and set up a stimulus controller if I don’t find a fix for it.

Thank you both for helping!

Cheers!

1 Like