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

Issue fork webform-3567475

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tuuuukka created an issue. See original summary.

tuuuukka’s picture

Status: Active » Needs review
liam morland’s picture

Thanks for catching this. Are you able to add a test for this?

tuuuukka’s picture

Status: Needs review » Needs work

Just noticed that the same issue is present in these files:

https://git.drupalcode.org/project/webform/-/blob/6.3.x/js/webform.eleme...
https://git.drupalcode.org/project/webform/-/blob/6.3.x/js/webform.eleme...

Those could be fixed in this same MR.

Are you able to add a test for this?

Probably yes, if I find the correct place to add the tests.

liam morland’s picture

Great. Thanks for finding those. It would be helpful to use git blame to find out the commit in which the problem code was added.

tuuuukka’s picture

Great. Thanks for finding those. It would be helpful to use git blame to find out the commit in which the problem code was added.

It's this one: https://git.drupalcode.org/project/webform/-/commit/b085c3af2699736782d4...

The issue: https://www.drupal.org/project/webform/issues/3493832

I guess the changes were added rather quickly and not much time was given to actually review and test them.

liam morland’s picture

Thanks for finding that. If you can add a test, that would be great.

schoenef’s picture

Hi Team, so what is needed for this one to be merged?

liam morland’s picture

It should have a test.

liam morland’s picture

Status: Needs work » Fixed
Issue tags: -Needs tests

I have committed this fix. Tests should be added in the parent issue. I did the fix without waiting for a test because it was fixing a feature that was committed without a test.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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