-
Notifications
You must be signed in to change notification settings - Fork 428
suggestion for turboforms #64
Comments
Let's start with having this be an external concern. I think most people using turbolinks would have ajax forms anyway, so it's not as important of a concern as the links themselves. But do start a separate turboforms project that depends on turbolinks. If you have any specific recommendations on how the turbolinks api could be made better for something like turboforms, let us know. |
What is the actual easiest way to do so that when we submit a form, the page is not completely reloaded (like with internal links in turbolinks) ? |
@fklingler I'm away for the weekend but will try and put something together mon/tue next week |
Happy to hear about this form 'issue'. On a new project, I don't feel like it is that external. |
@dhh turbolinks is precisely the reason I'd want to not have ajax forms--because turbolinks should do it for me! 👍 +1 to re-opening this. |
The point with ajax forms is often to trigger custom JS on their submission, though. Hide this, show that. Those choices can't be automated. |
Agreed that it should not be the default. In @timurvafin's fs/turboform gem, he requires to add a |
Love to have extensions to this, but at this time I'm not thinking it's a fit for core. |
Fair enough, thanks for the reply 🍻 |
@moomerman - did you turn your extension into a gem yet? What's the status? |
@jeremyhaile haven't released anything yet I'm afraid, I had to make changes to my version of Turbolinks to support my extension and didn't get round to submitting that as a suggestion as I wasn't that happy with the changes I made, I just 'got it working'. |
Is it not just a case of something like the following that I'm currently using in a helper.js file included in application.js and applying $(document).on('submit', 'form[data-turbolinks-form]', function(e) {
var options = {};
Turbolinks.visit(
this.action + (this.action.indexOf('?') === -1 ? '?' : '&') + $(this).serialize(),
options
);
return false;
}); This could be extended to check for a |
@amnesia7 This isn't possible without adding a dependency on jQuery or a big chunk of code for doing form serialization (see #379). Both options aren't a good fit for Turbolinks. You can do the equivalent using jquery-ujs and server-side |
Actually the inners should probably all be within |
Sorry, page hadn't shown that you'd commented. |
@Thibaut if I use |
Turbolinks's progress bar API is public for that purpose yes.
Updating the current URL on For GET requests it makes sense to update the URL, though. I'll make the change soon. |
@Thibaut I'm not sure where to go with this in my case because any js browser could do the remote form submission but only those that support turbolinks would be able to interpret the turbolinks-centric response that is returned so I'm wondering how it would affect them. Wouldn't it cause them to wait for the remote form submission to return a response which the browser then wouldn't understand (because it doesn't support turbolinks) and cause the browser to reload the new url meaning that using the search for those browsers would take twice as long (and cause twice as many server hits) as it should? This is in contrast to my original jquery js would only be submitted via turbolinks if the browser supports turbolinks and the page would submit to the new search url if it didn't. I'm all in favour of using the rails tools that we have (turbolinks, ujs, etc) but I'm not sure that it beats the jquery code that I mentioned above unless you can convince me otherwise. |
@amnesia7 Yes, Ideas are welcome for ways to get around that. For now my position is that it's your responsibility to check for Your solution adds a dependency on jQuery and only works with GET forms. If it works for you, great, that's exactly the kind of thing Turbolinks 3 wants to enable devs to easily do, but it's not something we'd want to add to Turbolinks core. Once I make the change to update the URL on GET +
|
@Thibaut updating turbolinks to allow for GET forms would be great. If I want to update the whole body (so that the search form query field can stay in tune with the url between page changes once the fix has been applied) then $(document).on('page:load page:restore', function () {
Turbolinks.ProgressBar.done();
}); because this doesn't seem to be firing as it currently stands. |
I've got an implementation of turboforms working which hijacks all 'normal' forms on the page and sends then asynchronously, replacing the body with the result. This example is rails-specific but could be made generic:
It raises two questions
The text was updated successfully, but these errors were encountered: