Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lars-Janssen's avatar

Turbolinks with is-loading

Hi,

I've migrated my webapp to use turbolinks.

First when a form was submited I the button was disabled:

$("form").submit(() => {
    $("#submit").addClass("is-loading");
    return true;
});

But that's not working anymore. Any idea how I could bypass this?

0 likes
1 reply
MikeHopley's avatar

Your javascript only runs once, when the page is loaded. That's when it attaches the event handler.

With turbolinks, this will not work properly, because it replaces a page fragment that (I assume) does not include your javascript. The javascript will not execute a second time, so any new forms will not have the event handler attached.

You will need to change your code to account for this. One option would be to include an initialise() function with every HTML fragment that turbolinks fetches, and then from that function you could call all your "setup" code.

I haven't actually used turbolinks, so there may be better ways I'm not aware of.

Please or to participate in this conversation.