You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a form that is invisible to the user, no submit button, but with data-turbo=true set on it. It is used to handle a QR code scan to send the results of the scan back to the server. So upon a QR scan, an input in the form gets set to the value of the scan, and then form.requestSubmit() is called. But Turbo does not do anything to intercept this submission. I am trying to do a turbo stream response from the server, but the turbo stream mime type is not getting added to the accept header.
I think I've tracked down the reason for this. When my form.requestSubmit() gets called, this should run:
form will be set, but submitter will not, because I'm not passing in a submitter in my form.requestSubmit() call (primarily because I don't have a submitter, no submit button on this form currently).
this.elementDriveEnabled(form) should return true because I have data-turbo=true set on the form. But this.elementDriveEnabled(submitter) when submitter is undefined, what will it return?
First it's closest [data-turbo] is found, which will be undefined, because it itself is undefined, and then the answer depends entirely on what Turbo.session.drive is set to, which in my case is false.
Now, what I've discovered through the process of writing this issue is that form.requestSubmit()should default submitter to the form if one is not provided, but that is not the behavior I'm seeing in the latest Chrome, or in the latest Safari. Both of them pass null as the submitter which gets turned into undefined here:
If the browsers were behaving like the documentation says that they should, I would not have run into this issue. But, in my opinion, I think it would make sense that if there is no submitter, that the answer of willSubmitForm should be based solely on the form.
willSubmitForm(form: HTMLFormElement,submitter?: HTMLElement): boolean {returnthis.elementDriveEnabled(form)&&(!submitter||this.elementDriveEnabled(submitter))}// or more clearlywillSubmitForm(form: HTMLFormElement,submitter?: HTMLElement): boolean {if(submitter){returnthis.elementDriveEnabled(form)&&this.elementDriveEnabled(submitter)}else{returnthis.elementDriveEnabled(form)}}
edit:
I should just also include the workaround in case anyone else is running into this. I was unable to just pass the form element as the submitter, as Chrome (maybe other browsers would have as well) was raising an error. So I added a hidden submit button and passing that as the submitter in the requestSubmit() call.
form.requestSubmit(hiddenSubmitButton)
The text was updated successfully, but these errors were encountered:
On your new hidden submit button did you also have to add data-turbo=true? Based on my read of the current code, both the form and the submitter need this element for Turbo Drive to submit the form.
I have Turbo drive globally disabled in my app.
I have a form that is invisible to the user, no submit button, but with
data-turbo=true
set on it. It is used to handle a QR code scan to send the results of the scan back to the server. So upon a QR scan, an input in the form gets set to the value of the scan, and thenform.requestSubmit()
is called. But Turbo does not do anything to intercept this submission. I am trying to do a turbo stream response from the server, but the turbo stream mime type is not getting added to the accept header.I think I've tracked down the reason for this. When my
form.requestSubmit()
gets called, this should run:turbo/src/core/session.ts
Lines 190 to 192 in 11840c1
form
will be set, butsubmitter
will not, because I'm not passing in a submitter in myform.requestSubmit()
call (primarily because I don't have a submitter, no submit button on this form currently).this.elementDriveEnabled(form)
should return true because I havedata-turbo=true
set on the form. Butthis.elementDriveEnabled(submitter)
when submitter is undefined, what will it return?turbo/src/core/session.ts
Lines 305 to 324 in 11840c1
First it's closest
[data-turbo]
is found, which will be undefined, because it itself is undefined, and then the answer depends entirely on whatTurbo.session.drive
is set to, which in my case isfalse
.Now, what I've discovered through the process of writing this issue is that
form.requestSubmit()
should defaultsubmitter
to the form if one is not provided, but that is not the behavior I'm seeing in the latest Chrome, or in the latest Safari. Both of them passnull
as thesubmitter
which gets turned intoundefined
here:turbo/src/observers/form_submit_observer.ts
Lines 33 to 36 in 11840c1
If the browsers were behaving like the documentation says that they should, I would not have run into this issue. But, in my opinion, I think it would make sense that if there is no submitter, that the answer of
willSubmitForm
should be based solely on the form.edit:
I should just also include the workaround in case anyone else is running into this. I was unable to just pass the form element as the submitter, as Chrome (maybe other browsers would have as well) was raising an error. So I added a hidden submit button and passing that as the submitter in the
requestSubmit()
call.The text was updated successfully, but these errors were encountered: