I have a search form on my page, and it is safe for Turbolinks to be enabled as it is using method="get"
Is there any easy way to have the form submit under control of Turbolinks (ie avoid page refresh)
You could use something like this in your application.js
:
// send get forms through turbolinks
$(document).on("submit", "form[data-turboform]", function(e) {
Turbolinks.visit(this.action+(this.action.indexOf('?') == -1 ? '?' : '&')+$(this).serialize());
return false;
});
Then, to enable any form to be sent with turbolinks you would need to add the data-turboform
attribute to the form, like this:
<form action="..." method="get" data-turboform>
...
</form>
At the turbolinks project, there's issue #64 where someone has written a Coffeescript implementation for Rails.
Add the code provided at that link.
It adds a turboforms
function that needs to be called at page ready, like this:
$(turboforms);
I'm in the process of implementing this, I'll update my answer if I find out anything else that's useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With