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.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 3010084-19.patch | 5.37 KB | jrockowitz |
| #18 | 3010084-17.patch | 4.8 KB | jrockowitz |
| #15 | 3010084-15.patch | 4.75 KB | jrockowitz |
| #13 | 3010084-14.patch | 4.68 KB | jrockowitz |
| #9 | 3010084-6.patch | 3.33 KB | jasonrust |
Comments
Comment #2
jasonrust commentedComment #3
jrockowitz commentedThis 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
Comment #4
jasonrust commentedThanks 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.
Comment #5
jrockowitz commentedMy 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.
Comment #6
jrockowitz commentedThe 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.
Comment #7
jasonrust commentedSeriously 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.Comment #8
jasonrust commentedheh, just figured out that it is supposed to be "removeData". I changed it to that and it still works.
Comment #9
jasonrust commentedAttaching 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.
Comment #10
jrockowitz commentedI am completely stumped on how to block the Ajax submit callback.
Comment #11
jrockowitz commentedI posted How to prevent an Ajax form from submitting in Drupal 8? on Drupal Answers.
Comment #12
jrockowitz commentedI might have found the answer.
@see #2952233: Apply client side validation on forms submitted via ajax
Comment #13
jrockowitz commentedThe attached patch includes Ajax support.
Comment #15
jrockowitz commentedComment #16
jasonrust commentedTested 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
Comment #17
jrockowitz commented@jasonrust Thanks for catching that Likert mistake.
I am going to do some more testing and make a few more tweaks.
Comment #18
jrockowitz commentedThis patch should account for #3007890: File Upload field in repeatable custom composite
Comment #19
jrockowitz commentedThis patch accounts for #3007890: File Upload field in repeatable custom composite.
Comment #21
jrockowitz commentedI retested and committed the patch. Please download the latest dev release to review.
Comment #22
jrockowitz commented@jasonrust Congratulations on earning your first commit credit
I wanted the say "Thanks" for helping out with the Webform module. Learn more about...