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
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
Comment #3
tuuuukka commentedComment #4
liam morlandThanks for catching this. Are you able to add a test for this?
Comment #5
tuuuukka commentedJust 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.
Probably yes, if I find the correct place to add the tests.
Comment #6
liam morlandGreat. Thanks for finding those. It would be helpful to use
git blameto find out the commit in which the problem code was added.Comment #7
tuuuukka commentedIt'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.
Comment #8
liam morlandThanks for finding that. If you can add a test, that would be great.
Comment #9
schoenef commentedHi Team, so what is needed for this one to be merged?
Comment #10
liam morlandIt should have a test.
Comment #13
liam morlandI 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.