When a file field is part of a form the submission of the form does not wait for the file upload to complete.

Repro steps:

* Create a form with a file upload component.
* Attach a large file that will take some time to upload
* Click the submit button
* Note that the form is submitted before the file has finished uploading and that the submission does not have a file attached.

This happens regardless of whether AJAX submission is enabled or disabled. This was not an issue until I upgraded from rc22 to rc24.

I am using private file uploads and Drupal 8.6.2 and Chrome 69.

Comments

jasonrust created an issue. See original summary.

jasonrust’s picture

Issue summary: View changes
jrockowitz’s picture

This is a core issue but there might be an easy workaround where we disable the webform's submit buttons during a file upload.

@see #2869855: Race condition in file_save_upload causes data loss

jasonrust’s picture

Thanks for the link. I tried the patch at the bottom of that issue, but it didn't solve it, so I'll keep an eye on the issue. If it's easy to disable the submit button in webform until it completes that would work. Another possibility would be to change it from an AJAX upload to regular POST, but I haven't found any way to do that. Do you know if that's a possibility? Thanks.

jrockowitz’s picture

My concern about disabling the form's submit button during a file upload is if the file upload fails the user can't submit the form.

jrockowitz’s picture

StatusFileSize
new3.33 KB

The attached patch tracks inprogress file uploads and displays a confirmation dialog when a user attempts to submit the form.

I don't think the current solution works with form's submitted via Ajax.

jasonrust’s picture

Seriously huge thanks! You're right it doesn't work with AJAX submissions, but it does with regular submissions, with the caveat that I had to comment out the line $(this).remoteData('msk-auto-file-upload') as it complained that remoteData isn't a method.

jasonrust’s picture

heh, just figured out that it is supposed to be "removeData". I changed it to that and it still works.

jasonrust’s picture

StatusFileSize
new3.33 KB

Attaching a revised version of the patch that changes remoteData to removeData for those that need it while waiting for the drupal core issue to resolve.

jrockowitz’s picture

I am completely stumped on how to block the Ajax submit callback.

jrockowitz’s picture

jrockowitz’s picture

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new4.68 KB

The attached patch includes Ajax support.

Status: Needs review » Needs work

The last submitted patch, 13: 3010084-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new4.75 KB
jasonrust’s picture

Tested the latest and confirmed it works with both ajax and non-ajax. There is one line in that patch that seems to be an inadvertent change: src/Plugin/WebformElement/WebformLikert.php

jrockowitz’s picture

@jasonrust Thanks for catching that Likert mistake.

I am going to do some more testing and make a few more tweaks.

jrockowitz’s picture

StatusFileSize
new4.8 KB
jrockowitz’s picture

StatusFileSize
new5.37 KB

  • jrockowitz committed 993ca2e on 8.x-5.x
    Issue #3010084 by jrockowitz, jasonrust: Form submission finishes before...
  • jrockowitz committed ccc727c on 8.x-5.x
    Issue #3010084 by jrockowitz, jasonrust: Form submission finishes before...
jrockowitz’s picture

Status: Needs review » Fixed

I retested and committed the patch. Please download the latest dev release to review.

jrockowitz’s picture

@jasonrust Congratulations on earning your first commit credit

I wanted the say "Thanks" for helping out with the Webform module. Learn more about...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.