I have found a problem that when more than one instance of dropzonejs field is added to a single form, only the first one is properly initiated.
The second one has no functionality attached.

Steps to reproduce:

1. Create a new custom form
2. Add dropzonejs field twice, e.g.

$form['dropzonejs_first'] = [
      '#title' => t('DropzoneJs element'),
      '#type' => 'dropzonejs',
      '#required' => TRUE,
      '#dropzone_description' => 'DropzoneJs description',
      '#max_filesize' => '1M',
      '#extensions' => 'jpg png',
    ];

$form['dropzonejs_second'] = [
      '#title' => t('DropzoneJs element'),
      '#type' => 'dropzonejs',
      '#required' => TRUE,
      '#dropzone_description' => 'DropzoneJs description',
      '#max_filesize' => '1M',
      '#extensions' => 'jpg png',
    ];

3. Only first instance of the field is initiated, the second one has to behaviours attached.

CommentFileSizeAuthor
#3 cannot_instantiate-2798543-3.patch6.42 KBchr.fritsch
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

turtletrail created an issue. See original summary.

Primsi’s picture

Issue tags: +D8Media
chr.fritsch’s picture

Version: 8.x-1.0-alpha2 » 8.x-1.x-dev
Status: Active » Needs review
FileSize
6.42 KB

Not sure if this is all, but it seems to work

Andrew211’s picture

Thanks @chr.fritsch works a treat, uploaded 2 years ago and still not "8.x-2.0-alpha3 released 14 December 2017", bizarre.

SocialNicheGuru’s picture

idebr’s picture

Yep, I closed the related issue as a duplicate.

FirstSanny’s picture

Works like a charm. Thanks a lot. You saved me a lot of trouble.
Tested with Drupal core 8.6.3 and dropzonejs 8.x-2.0-alpha3.

genellann’s picture

Which patch should I use? The one from this thread, #3 by chr.fritsch, or the one from the duplicate bug thread, #2 by idebr?

genellann’s picture

This patch (#3 by chr.fritsch) worked for me. The other (#2 by idebr on dup) did not work.

ainarend’s picture

Can confirm that the patch #3 resolves the issue.

chr.fritsch’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev

Moving to 2.x

chr.fritsch’s picture

Status: Needs review » Reviewed & tested by the community

Setting to RTBC based on #7, #9 and #10

  • chr.fritsch committed 4e9f2b6 on 8.x-2.x
    Issue #2798543 by chr.fritsch: Cannot instantiate several instances of...
chr.fritsch’s picture

Status: Reviewed & tested by the community » Fixed

Fixed

Status: Fixed » Closed (fixed)

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

Joe Huggans’s picture

Thank you for this, absolute lifesavers.

Joe Huggans’s picture

I believe I have found a bug with this, albeit an edge case.

If you upload 2 files with the same filename, one of each into 2 dropzones, then the second dropzone field is empty when looking at the $form_state