Add element fails with "An AJAX HTTP error occurred.". The dialog to select element cannot be opened

Created on 31 May 2025, 8 days ago

Problem/Motivation

If I create a new webform and try to add an element, an error occurs. In the browser console the following error is displayed:
"\nAn AJAX HTTP error occurred.\nHTTP Result Code: 200\nDebugging information follows.\nPath: /de/admin/structure/webform/manage/public_tff3/element/add\nStatusText: parsererror\nResponseText: \nWarning: Undefined array key \"#webform_key\" in /var/www/html/web/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php on line 298\nWarning: Undefined array key \"#webform_key\" in /var/www/html/web/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php on line 298\nWarning: Undefined array key \"#webform_key\" in /var/www/html/web/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php on line 298\nWarning: Undefined array key \"#webform_key\" in /var/www/html/web/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php on line 298\nWarning: Undefined array key \"#webform_key\" in /var/www/html/web/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php on line 298
....

Steps to reproduce

1) Create a new webform
2) Add an element by pressing the "Add element" button
3) The dialog with the available elements should open, but nothing happens...

Proposed resolution

The error says, that the "#webform_key" in the array is missing on line 298 in file /web/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php.
Here the failing code part.

    // Allow ManagedFile Ajax callback to disable flexbox wrapper.
    // @see \Drupal\file\Element\ManagedFile::uploadAjaxCallback
    // @see \Drupal\webform\Plugin\WebformElementBase::preRenderFixFlexboxWrapper
    $request_params = \Drupal::request()->request->all();
    if (\Drupal::request()->request->get('_drupal_ajax') && (!empty($request_params['files']) || !empty($request_params[$element['#webform_key']]))) {
      $element['#webform_wrapper'] = FALSE;
    }

The elements in the Add-element-dialog are not attached to a webform, so the #webform_key is missing.
Possible solution:
If we add another check to the if-statement, the dialog works again:

   $request_params = \Drupal::request()->request->all();
    if (\Drupal::request()->request->get('_drupal_ajax') <strong>&& isset($element['#webform_key'])</strong> && (!empty($request_params['files']) || !empty($request_params[$element['#webform_key']]))) {
      $element['#webform_wrapper'] = FALSE;
    }
🐛 Bug report
Status

Active

Version

6.3

Component

Code

Created by

🇨🇭Switzerland ralph_moser

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024