This repository has been archived by the owner on Sep 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
Best practices for GET remote form submit #132
Comments
In our app we just build and use an |
We listen to the ajax:create event created by rails-ujs remote form submit event like so
This was implemented in a very old rails application using prototype. So you need to adapt this to jQuery/vanillajs if you do not use prototype. This is all done on the server and only when the native apps request the pages. |
We do this (CoffeeScript and jQuery), adding a # Makes GET forms work with Turbolinks, by simply visiting the URL they would submit to.
$(document).on "submit", ".js-turbolinks-get-form", (e) ->
url = $(this).attr("action") + "?" + $(this).serialize()
Turbolinks.visit(url)
e.preventDefault() |
FWIW, we added the following (very similar to @henrik's solution, just doesn't require additional class on form): $(document).on "submit", "form[method=get][data-remote=true]", (e) ->
e.preventDefault()
url = this.action + '?' + $(this).serialize()
Turbolinks.visit url
false |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
We have a search form that uses GET to filter on the collection:
The response itself is a normal Rails action returning the entire template. It looks like I incorrectly assumed Turbolinks would handle this similar to a link.
What's the best practice around modifying search-style forms?
The text was updated successfully, but these errors were encountered: