Impossible to add custom options to Select2 due to undefined variable

Created on 14 January 2026, 7 days ago

Problem/Motivation

In https://git.drupalcode.org/project/webform/-/blob/6.3.x/js/webform.eleme... you can see that $input is used, but it's actually never defined This leads to an error in console when you add data-options attribute to the corresponding element:

Uncaught ReferenceError: $input is not defined

The element also turns in to a regular element instead of a Select2 element.

Steps to reproduce

Apply this diff:

diff --git a/src/Element/WebformPermissions.php b/src/Element/WebformPermissions.php
index dc0ebb3f9..86375f199 100644
--- a/src/Element/WebformPermissions.php
+++ b/src/Element/WebformPermissions.php
@@ -43,6 +43,7 @@ class WebformPermissions extends Select {
     }
     $element['#options'] = $options;
     $element['#select2'] = TRUE;
+    $element['#attributes']['data-options'] = json_encode(['placeholder' => 'Select something']);

     // Must convert this element['#type'] to a 'select' to prevent
     // "Illegal choice %choice in %name element" validation error.

Open up any form and go to Settings -> Access. Here you can see that the Permissions fields are not working as they should and that there's the error in console.

Proposed resolution

Use $select instead of $input, as that's the element we want to target here.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

6.3

Component

Code

Created by

🇫🇮Finland Tuuuukka

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024