Even though this is not inherent to DropzoneJS, but rather to Drupal core Javascript + Chrome, I experienced it heavily when using FileBrowser + DropzoneJS.

The problem

Validation error is triggered when double-clicking on "Select entities", the message displayed is:
"At least one valid file should be uploaded.".
This is the case for the Chrome web-browser, Firefox seems to be fine.

Reproducing

You can easily reproduce this problem without killing your index-finger.

  1. Fire-up your Chrome
  2. Simply add a sleep(2) at the beginning of the DropzoneJsEbWidget::validate() function.
  3. Then click once on "Select entities" after dropping an image into your FileBrowser/Dropzone.
  4. Within the next two seconds click again on "Select entities".
  5. This should give you the validation error message "At least one valid file should be uploaded."

Solution
Use a two-sided extension to the form submission and validation constraints:

  • using the lock service on the server side
  • using javascript (e.g. jquery.form-submit-single) on the client side to ensure forms are submitted once, even while double-clicking in Chrome

References

Comments

stefanos.petrakis created an issue. See original summary.

stefanos.petrakis’s picture

Issue summary: View changes
stefanos.petrakis’s picture

A working patch coming up pretty soon

stefanos.petrakis’s picture

Adding some client-side, double-click prevention code from https://github.com/sun/jquery-form-submit-single.
And some locking/logging during validation for the DropzoneJsEbWidget.
Thanks to @beutlerk for reporting and testing this.

stefanos.petrakis’s picture

stefanos.petrakis’s picture

Issue summary: View changes
l0ke’s picture

Status: Active » Needs review
StatusFileSize
new7.8 KB

Re-rolling patch against latest dev.

grathbone’s picture

The patch from #7 seems to cause an issue with switching tabs on the Entity Browser dialog. Clicking other tabs doesn't do anything at all.

sanchiz’s picture

StatusFileSize
new4.51 KB

Re-rolled for latest 1.x dev.

@grathbone, I have no issues with other Entity Browser tabs.

sanchiz’s picture

I seems that in previous patch I missed some files. Re-rolled once again.

hamrant’s picture

Status: Needs review » Needs work

Looks like after drupal core update this patch not work anymore. I have used patch from #10 and all was fine. Now on my site drupal core is version 8.4.8 and dropzonejs same as before (1.0-alpha8), as result - form submit absolutely not working.

Quick investigation shows that `onFormSubmitSingle` function runs 2 times immediately: on first one it set current values and then prevent for submit

    if (previousValues === currentValues) {
      event.preventDefault();
    }
    else {
      $form.attr('data-form-submit-single-last', currentValues);
    }

This issue can be related to jquery update in drupal core. anyway it's need some work here.

Nik3D’s picture

StatusFileSize
new6.97 KB

Adding 'context' selector where 'onFormSubmitSingle' is being called fixes issue mentioned in #11.

Nik3D’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: dropzonejs-prevent_multiple_form_submissions-2833965-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Nik3D’s picture

StatusFileSize
new7.75 KB

Incorrect transliteration has been causing test fails lately.
Adding fix of incorrect transliteration in DropzoneJsUploadControllerTest.php file.

Nik3D’s picture

Status: Needs work » Needs review
daften’s picture

Update patch for dropzonejs 2.0.0-alpha4

daften’s picture

Update patch to include the js files again

Andrew Gorokhovets’s picture

Updated patch to include the js files for the latest dev version.

purushotam.rai’s picture

Quick Question/Thought:

Why are we creating our own version of onFormSubmitSingle, while we already have provision for "Drupal.behaviors.formSingleSubmit" provided by core/drupal.form

Merely adding following piece of code can do our work.

    $form['actions']['submit']['#attributes']['class'][] = 'singleSubmit';
    $form['#attached']['library'][] = 'core/drupal.form';
saso.sotlar’s picture

Updated patch from #19 so it could be used on D9.

Andrew Gorokhovets’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #21 looks good for me.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

Needs to be a merge request now. Not sure if the server side check is really needed, what's the benefit of that?

berdir’s picture

Assigned: stefanos.petrakis » Unassigned