Problem/Motivation

I just ran into #2872024: Managed File - Duplicate error messages when upload is failed and realized the the Managed file element is generating duplicate <div id="ajax-wrapper">.

Below is the output from the \Drupal\file\Tests\FileManagedFileElementTest::testManagedFile which include an <div id="ajax-wrapper"> around the form element and the input.

<div id="ajax-wrapper"><div class="js-form-item form-item js-form-type-managed-file form-type-managed-file js-form-item-nested-file form-item-nested-file">
      <label for="edit-nested-file-upload">Managed <em>file &amp; butter</em></label>
        
<div id="edit-nested-file-upload" class="js-form-managed-file form-managed-file">
  <div id="ajax-wrapper"><input data-drupal-selector="edit-nested-file-upload" type="file" id="edit-nested-file-upload" name="files[nested_file]" size="13" class="js-form-file form-file" />
<input class="js-hide button js-form-submit form-submit" data-drupal-selector="edit-nested-file-upload-button" formnovalidate="formnovalidate" type="submit" id="edit-nested-file-upload-button" name="nested_file_upload_button" value="Upload" />
<input data-drupal-selector="edit-nested-file-fids" type="hidden" name="nested[file][fids]" />
</div>
</div>

Proposed resolution

TBD

Remaining tasks

TBD

CommentFileSizeAuthor
#2 managed_file_element_is-2874707-2.patch875 bytesjrockowitz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jrockowitz created an issue. See original summary.

jrockowitz’s picture

The attached patch includes a assertion that confirms that there are duplicate ajax-wrapper IDs for the test managed file upload element.

cilefen’s picture

About every three months, we get another one of these. Is it a duplicate?

jrockowitz’s picture

Status: Active » Closed (duplicate)

This is absolutely a duplicate. Last night, I was getting punchy after assuming for an hour that the Webform was causing this issue.

benjifisher’s picture

Curiously, this is the issue that Google finds when I search for "drupal duplicate id ajax".

I also suspected the Webform module at first. After checking that it was the original markup (not modified by javascript) causing the error, and knowing that Webform uses the Form API, I figured it might be a core bug. I upgraded to the current version of Drupal (8.4.4) and the problem went away.