question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

data-turbo-action is not respected on requestSubmit() event from javascript

See original GitHub issue

Hi 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tbeemstercommented, Sep 30, 2022

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-frame table. Since that form also has data-turbo-action="advance" the URL of that form submission will also be placed in the browser’s URL bar)

html-with-description

0reactions
tbeemstercommented, Oct 3, 2022

Thanks a lot

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found