data-turbo-action is not respected on requestSubmit() event from javascript
See original GitHub issueHi there,
While updating turbo to version 7.2 today, I discovered a bug.
Before upgrading to version 7.2, after calling requestSubmit()
on the form via javascript, for example by clicking on the option “25” in the select box, Turbo would change the window location
into something like /page?page_size=25
However, after performing the same steps with Turbo 7.2, the window location is not updated, and stays /page
I’ve added a reduced snippet of HTML and JS to illustrate the problem.
If you need any additional information to debug the problem, I’m happy to supply extra information. Thanks for your great product! 😃
<form action="/page" method="GET" data-turbo-action="advance" id="filter-table"></form>
<select name="page_size" data-controller="select" form="filter-table">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
</select>
The select_controller.js has a small snippet of javascript that will invoke requestSubmit() when the value of the select has changed.
...
export default class SelectController extends Controller {
connect () {
...
this.htmlInput.listen('MDCSelect:change', () => {
htmlInput.form.requestSubmit()
})
...
}
disconnect () {
...
}
}
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
HTMLFormElement.requestSubmit() - Web APIs | MDN
The HTMLFormElement method requestSubmit() requests that the form be submitted using a specific submit button.
Read more >Javascript alternative for requestSubmit(). Since safari does ...
In Javascript I changed .requestSubmit() to .submit() . And added dispatch event to trigger the event. /** * When pressed enter, next part ......
Read more >Releases · hotwired/turbo - GitHub
... Fix data-turbo-action was not respected on requestSubmit() event from javascript by @seanpdoyle in #749; Reload page if failed form changes tracked ...
Read more >Navigate with Turbo Drive - Hotwire Turbo
Turbo Drive accelerates links and form submissions by negating the need for full page reloads.
Read more >submit() vs. requestSubmit() - Fun with forms
This is not to be confused with the submit event. Unlike submit() it does handle validation and will only trigger if the form...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @seanpdoyle,
I think you are correct in your findings. I have attached a beautiful picture, which hopefully shows you how I’m using this.
(By changing the select box, the “filter-table-form” is submitted. Since that form has
data-turbo-frame="table"
, the response of that form will be parsed in the turbo-frametable
. Since that form also hasdata-turbo-action="advance"
the URL of that form submission will also be placed in the browser’s URL bar)Thanks a lot