Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress bar not displayed when submitting a form #61

Closed
coorasse opened this issue Dec 30, 2020 · 5 comments · Fixed by #317
Closed

Progress bar not displayed when submitting a form #61

coorasse opened this issue Dec 30, 2020 · 5 comments · Fixed by #317

Comments

@coorasse
Copy link
Contributor

I noticed that the progress bar is not displayed when submitting a form.
While trying to understand the reason, I noticed that showProgressBarAfterDelay is called only after the submit is finished.
The method is called by visitRequestStarted, called by startRequest, and by keep going back into the stack, they are called into formSubmissionSucceededWithResponse, so when the submit is already terminated.

The result is that the progress ber is not displayed.

Is this a bug, or did I miss something?

@jeffochoa
Copy link

I'm having the same issue, it looks like you have to redirect AFTER handling the form-submission:

Turbo Drive handles form submissions in a manner similar to link clicks. The key difference is that form submissions can issue stateful requests using the HTTP POST method, while link clicks only ever issue stateless HTTP GET requests.

After a stateful request from a form submission, Turbo Drive expects the server to return an HTTP 303 redirect response, which it will then follow and use to navigate and update the page without reloading.

That doesn't work for me because I want to redirect the users to a different page, and that extra request is not ideal.

An option for me would be to disable Turbo on the actual form, but right now that's not possible, although there is an open PR for that #3

Hopefully that one will get merged soon 🤞

@coorasse please let me know if you find a workaround for this issue.

Cheers,
Jeff.

@jeffochoa
Copy link

Ok, I found a temporal solution. Using the custom turbo events, you can capture the submit-start to load the progress-bar manually as follows:

<script>
    document.addEventListener('turbo:submit-start', function () {
        Turbo.navigator.delegate.adapter.showProgressBar();
    });
</script>

@sudara
Copy link

sudara commented Jan 12, 2021

I posted on the Hotwire forums asking whether it should be default for the progress bar to always show on form submission. Otherwise, repeatedly rejected forms can appear as no-ops...

@wnm
Copy link

wnm commented Feb 5, 2021

Ok, I found a temporal solution. Using the custom turbo events, you can capture the submit-start to load the progress-bar manually as follows:

<script>
    document.addEventListener('turbo:submit-start', function () {
        Turbo.navigator.delegate.adapter.showProgressBar();
    });
</script>

Is this still working for the latest version of Turbo? I'm loading Turbo via the hotwire-rails gem (and via the asset pipeline) and I get a Turbo is not defined error....

seanpdoyle added a commit to seanpdoyle/turbo that referenced this issue Feb 7, 2021
Closes hotwired#61
Closes hotwired#147

---

Extends the `Adapter` interface to support new
`formSubmissionStarted(FormSubmission)` and
`formSubmissionFinished(FormSubmission)` delegate methods to hook into a
page's form submission lifecycle. Making the Adapter aware of form
submissions provides an opportunity to show and hide the progress bar in
the same way as driving the page with Visits.

Additionally, replace the `HTMLDivElement` implementation of the
progress bar with a [progress][] element and an instance of
[HTMLProgressElement][]. When updating the progress, set the
`HTMLProgressElement.value` attribute, and let the browser-native
implementation update its width. Since the element's `value` attribute
is accessible via a property, we no longer have to synchronize via
`requestAnimationFrame()`.

To support the built-in element, there are some proprietary
pseudoelements to consider across the browsers, including:

* [-moz-progress-bar][] for the Firefox bar
* [-webkit-progress-bar][] for the Safari and Chrome bar background
* [-webkit-progress-value][] for the Safari and Chrome bar progress
* [-ms-fill][] for IE bars

[progress]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress
[HTMLProgressElement]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement
[-moz-progress-bar]: https://developer.mozilla.org/en-US/docs/Web/CSS/::-moz-progress-bar
[-webkit-progress-bar]: https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-progress-bar
[-webkit-progress-value]: https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-progress-value
[-ms-fill]: https://developer.mozilla.org/en-US/docs/Archive/Web/CSS/::-ms-fill
seanpdoyle added a commit to seanpdoyle/turbo that referenced this issue Feb 7, 2021
Closes hotwired#61
Closes hotwired#147

---

Extends the `Adapter` interface to support new
`formSubmissionStarted(FormSubmission)` and
`formSubmissionFinished(FormSubmission)` delegate methods to hook into a
page's form submission lifecycle. Making the Adapter aware of form
submissions provides an opportunity to show and hide the progress bar in
the same way as driving the page with Visits.

Additionally, replace the `HTMLDivElement` implementation of the
progress bar with a [progress][] element and an instance of
[HTMLProgressElement][]. When updating the progress, set the
`HTMLProgressElement.value` attribute, and let the browser-native
implementation update its width. Since the element's `value` attribute
is accessible via a property, we no longer have to synchronize via
`requestAnimationFrame()`.

To support the built-in element, there are some proprietary
pseudoelements to consider across the browsers, including:

* [-moz-progress-bar][] for the Firefox bar
* [-webkit-progress-bar][] for the Safari and Chrome bar background
* [-webkit-progress-value][] for the Safari and Chrome bar progress
* [-ms-fill][] for IE bars

[progress]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress
[HTMLProgressElement]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement
[-moz-progress-bar]: https://developer.mozilla.org/en-US/docs/Web/CSS/::-moz-progress-bar
[-webkit-progress-bar]: https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-progress-bar
[-webkit-progress-value]: https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-progress-value
[-ms-fill]: https://developer.mozilla.org/en-US/docs/Archive/Web/CSS/::-ms-fill
seanpdoyle added a commit to seanpdoyle/turbo that referenced this issue Feb 7, 2021
Closes hotwired#61
Closes hotwired#147

---

Extends the `Adapter` interface to support new
`formSubmissionStarted(FormSubmission)` and
`formSubmissionFinished(FormSubmission)` delegate methods to hook into a
page's form submission lifecycle. Making the Adapter aware of form
submissions provides an opportunity to show and hide the progress bar in
the same way as driving the page with Visits.

Additionally, replace the `HTMLDivElement` implementation of the
progress bar with a [progress][] element and an instance of
[HTMLProgressElement][]. When updating the progress, set the
`HTMLProgressElement.value` attribute, and let the browser-native
implementation update its width. Since the element's `value` attribute
is accessible via a property, we no longer have to synchronize via
`requestAnimationFrame()`.

To support the built-in element, there are some proprietary
pseudoelements to consider across the browsers, including:

* [-moz-progress-bar][] for the Firefox bar
* [-webkit-progress-bar][] for the Safari and Chrome bar background
* [-webkit-progress-value][] for the Safari and Chrome bar progress
* [-ms-fill][] for IE bars

[progress]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress
[HTMLProgressElement]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement
[-moz-progress-bar]: https://developer.mozilla.org/en-US/docs/Web/CSS/::-moz-progress-bar
[-webkit-progress-bar]: https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-progress-bar
[-webkit-progress-value]: https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-progress-value
[-ms-fill]: https://developer.mozilla.org/en-US/docs/Archive/Web/CSS/::-ms-fill
@todddickerson
Copy link

@wnm try

import { Turbo } from "@hotwired/turbo-rails"
window.Turbo = Turbo // Turbo available throughout app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants