diff --git a/inc/html.class.php b/inc/html.class.php
index 16064f4757d5..4c4347415be1 100644
--- a/inc/html.class.php
+++ b/inc/html.class.php
@@ -4333,15 +4333,6 @@ static function jsAdaptDropdown($id, $params = []) {
$templateresult = $params["templateResult"] ?? "templateResult";
$templateselection = $params["templateSelection"] ?? "templateSelection";
- $search_autofocus_event = << {
- const select2_selector = `.select2-search__field[aria-controls='select2-\${e.target.id}-results']`;
- $(select2_selector).each((k, v) => {
- v.focus();
- });
- });
-JS;
-
$js = "$(function() {
const select2_el = $('#$id').select2({
$placeholder
@@ -4435,7 +4426,7 @@ static function jsAdaptDropdown($id, $params = []) {
$('#$id').val(value).trigger('change');
})
$('label[for=$id]').on('click', function(){ $('#$id').select2('open'); });
- $search_autofocus_event
+ $(`.select2-search__field[aria-controls='select2-\${e.target.id}-results']`).focus();
});";
return Html::scriptBlock($js);
}
@@ -4520,15 +4511,6 @@ static function jsAjaxDropdown($name, $field_id, $url, $params = []) {
$options[$tag] = $val;
}
- $search_autofocus_event = << {
- const select2_selector = `.select2-search__field[aria-controls='select2-\${e.target.id}-results']`;
- $(select2_selector).each((k, v) => {
- v.focus();
- });
- });
-JS;
-
$output = '';
$js = "
@@ -4619,7 +4601,7 @@ static function jsAjaxDropdown($name, $field_id, $url, $params = []) {
}
$js .= " $('label[for=$field_id]').on('click', function(){ $('#$field_id').select2('open'); });";
- $js .= $search_autofocus_event;
+ $js .= " $(`.select2-search__field[aria-controls='select2-\${e.target.id}-results']`).focus();";
$output .= Html::scriptBlock('$(function() {' . $js . '});');