-
Notifications
You must be signed in to change notification settings - Fork 435
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
Fire turbo:click
event when submitting <form method="get">
#421
Fire turbo:click
event when submitting <form method="get">
#421
Conversation
Prior to this change, navigating a page via an `<a>` element and navigating a page via a `<form method="get">` element both resulted in `turbo:visit` events. However, clicking an `<a>` fired a `turbo:click` event, whereas submitting a `<form method="get">` by clicking its `<input type="submit">` or `<button>` element _did not_ fire the click for the submitter. This commit adds support for firing `turbo:click` events for a `<form method="get">` element's submitter.
I wouldn't expect a form submission, even if its a GET method, to trigger turbo:click, when other form submissions do not. What gave rise to wanting this? |
Form submissions with GET are a bit of an odd duck. Clicking on an
Submitting a
Submitting a
This proposed change was motivated by a desire to have parity between clicking a There are, of course, the native browser events that precede the My worry is that the lack of consistency between navigational event sequences initiated by |
It is an odd duck, but making get-forms fire turbo:click doesn't quite make sense to me. I get that they under the good are actually more like links than forms, but that's not how a user would think of it. If anything, it should fire more of the same like post-forms. But I also think that maybe it's just fine as it is? It is a bit of a hybrid, so imo OK that it has a different event stack. |
For consistency, I would think if a form is submitting (regardless if it's a get or post) the expectation would be any of the events related to a form submitting would be fired. So if there were to be a change, I'd vote for submitting a |
Closes hotwired#421 Closes hotwired#122 --- Fire the same sequence of events for `<form method="get">` submissions as for `<form method="post">` submissions. The [FormSubmission.prepareHeadersForRequest][] already accounts for `[method="get"]` forms by omitting the `Accept:` header with the custom `turbo-stream` MIME type. Test changes --- The `eventLogs` mechanisms we have in place declared in `src/tests/fixutres/test.js` cannot properly serialize `Element` instances, so adding `turbo:submit-start` and `turbo:submit-end` listeners to serialize events for our test suite isn't possible in the current configuration. To that end, this commit adds assertions for `<form>` submit event sequences for all events except those two. In their place, the suite adds listeners to set `[data-form-submit-start]` and `[data-form-submit-end]` to the `<html>` element when they fire. [FormSubmission.prepareHeadersForRequest]: https://github.com/hotwired/turbo/blob/58d2261274533a80a2c5efda7da211b3f20efcbb/src/core/drive/form_submission.ts#L136-L144
I've opened #424 as an alternative to this change. It changes |
Closes hotwired#421 Closes hotwired#122 --- Fire the same sequence of events for `<form method="get">` submissions as for `<form method="post">` submissions. The [FormSubmission.prepareHeadersForRequest][] already accounts for `[method="get"]` forms by omitting the `Accept:` header with the custom `turbo-stream` MIME type. Test changes --- The `eventLogs` mechanisms we have in place declared in `src/tests/fixutres/test.js` cannot properly serialize `Element` instances, so adding `turbo:submit-start` and `turbo:submit-end` listeners to serialize events for our test suite isn't possible in the current configuration. To that end, this commit adds assertions for `<form>` submit event sequences for all events except those two. In their place, the suite adds listeners to set `[data-form-submit-start]` and `[data-form-submit-end]` to the `<html>` element when they fire. [FormSubmission.prepareHeadersForRequest]: https://github.com/hotwired/turbo/blob/58d2261274533a80a2c5efda7da211b3f20efcbb/src/core/drive/form_submission.ts#L136-L144
Closes hotwired#421 Closes hotwired#122 --- Fire the same sequence of events for `<form method="get">` submissions as for `<form method="post">` submissions. The [FormSubmission.prepareHeadersForRequest][] already accounts for `[method="get"]` forms by omitting the `Accept:` header with the custom `turbo-stream` MIME type. Test changes --- The `eventLogs` mechanisms we have in place declared in `src/tests/fixutres/test.js` cannot properly serialize `Element` instances, so adding `turbo:submit-start` and `turbo:submit-end` listeners to serialize events for our test suite isn't possible in the current configuration. To that end, this commit adds assertions for `<form>` submit event sequences for all events except those two. In their place, the suite adds listeners to set `[data-form-submit-start]` and `[data-form-submit-end]` to the `<html>` element when they fire. [FormSubmission.prepareHeadersForRequest]: https://github.com/hotwired/turbo/blob/58d2261274533a80a2c5efda7da211b3f20efcbb/src/core/drive/form_submission.ts#L136-L144
Closes hotwired#421 Closes hotwired#122 --- Fire the same sequence of events for `<form method="get">` submissions as for `<form method="post">` submissions. The [FormSubmission.prepareHeadersForRequest][] already accounts for `[method="get"]` forms by omitting the `Accept:` header with the custom `turbo-stream` MIME type. Test changes --- The `eventLogs` mechanisms we have in place declared in `src/tests/fixutres/test.js` cannot properly serialize `Element` instances, so adding `turbo:submit-start` and `turbo:submit-end` listeners to serialize events for our test suite isn't possible in the current configuration. To that end, this commit adds assertions for `<form>` submit event sequences for all events except those two. In their place, the suite adds listeners to set `[data-form-submit-start]` and `[data-form-submit-end]` to the `<html>` element when they fire. [FormSubmission.prepareHeadersForRequest]: https://github.com/hotwired/turbo/blob/58d2261274533a80a2c5efda7da211b3f20efcbb/src/core/drive/form_submission.ts#L136-L144
Closes hotwired#421 Closes hotwired#122 --- Fire the same sequence of events for `<form method="get">` submissions as for `<form method="post">` submissions. The [FormSubmission.prepareHeadersForRequest][] already accounts for `[method="get"]` forms by omitting the `Accept:` header with the custom `turbo-stream` MIME type. Visit actions --- Prior to this change, a `<form method="get">` would _always_ result in two Visits: the first with `{ action: "advance" }`, then a second with `{ action: "replace" }`. Since the response to a `<form method="get">` has the potential to be a [200 OK][] or a [201 Created][], this commit also modifies the `Visit` class to skip the `followRedirect()` call when the request is idempotent and the response is not a redirect. Test changes --- The `eventLogs` mechanisms we have in place declared in `src/tests/fixutres/test.js` cannot properly serialize `Element` instances, so adding `turbo:submit-start` and `turbo:submit-end` listeners to serialize events for our test suite isn't possible in the current configuration. To that end, this commit adds assertions for `<form>` submit event sequences for all events except those two. In their place, the suite adds listeners to set `[data-form-submit-start]` and `[data-form-submit-end]` to the `<html>` element when they fire. [FormSubmission.prepareHeadersForRequest]: https://github.com/hotwired/turbo/blob/58d2261274533a80a2c5efda7da211b3f20efcbb/src/core/drive/form_submission.ts#L136-L144 [200 OK]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200 [200 Created]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201
Closes #421 Closes #122 --- Fire the same sequence of events for `<form method="get">` submissions as for `<form method="post">` submissions. The [FormSubmission.prepareHeadersForRequest][] already accounts for `[method="get"]` forms by omitting the `Accept:` header with the custom `turbo-stream` MIME type. Visit actions --- Prior to this change, a `<form method="get">` would _always_ result in two Visits: the first with `{ action: "advance" }`, then a second with `{ action: "replace" }`. Since the response to a `<form method="get">` has the potential to be a [200 OK][] or a [201 Created][], this commit also modifies the `Visit` class to skip the `followRedirect()` call when the request is idempotent and the response is not a redirect. Test changes --- The `eventLogs` mechanisms we have in place declared in `src/tests/fixutres/test.js` cannot properly serialize `Element` instances, so adding `turbo:submit-start` and `turbo:submit-end` listeners to serialize events for our test suite isn't possible in the current configuration. To that end, this commit adds assertions for `<form>` submit event sequences for all events except those two. In their place, the suite adds listeners to set `[data-form-submit-start]` and `[data-form-submit-end]` to the `<html>` element when they fire. [FormSubmission.prepareHeadersForRequest]: https://github.com/hotwired/turbo/blob/58d2261274533a80a2c5efda7da211b3f20efcbb/src/core/drive/form_submission.ts#L136-L144 [200 OK]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200 [200 Created]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201
Prior to this change, navigating a page via an
<a>
element andnavigating a page via a
<form method="get">
element both resulted inturbo:visit
events.However, clicking an
<a>
fired aturbo:click
event, whereassubmitting a
<form method="get">
by clicking its<input type="submit">
or<button>
element did not fire the click for thesubmitter.
This commit adds support for firing
turbo:click
events for a<form method="get">
element's submitter.