From 2486074e681505feee958e8f0ca02deda20eb0aa Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Mon, 15 Jun 2026 16:13:46 +0200 Subject: [PATCH 1/5] fix(tag_dropdown): fix tag dropdown to allow tag creation directly from the field --- CHANGELOG.md | 1 + inc/tag.class.php | 1 + public/js/modules/TagDropdownColorizer.js | 3 ++- templates/dropdown.html.twig | 21 ++++++++++----------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41cc544a..d98d43e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Prevent the tag field from appearing in the satisfaction survey. - Fix display translations - Removed tag rights during plugin uninstall +- Fix tag dropdown to allow tag creation directly from the field ## [2.14.3] - 2025-12-22 diff --git a/inc/tag.class.php b/inc/tag.class.php index 664b86d3..07e0650c 100644 --- a/inc/tag.class.php +++ b/inc/tag.class.php @@ -706,6 +706,7 @@ public static function showTagDropdown($params = []) 'extra_class' => $extra_class ?? '', 'selected_tags' => $selected_tags, 'available_tags' => $available_tags, + 'condition' => $where, 'tags_color' => $available_tags_color ?? [], 'rand' => $rand, 'token_creation' => $token_creation, diff --git a/public/js/modules/TagDropdownColorizer.js b/public/js/modules/TagDropdownColorizer.js index 38aa03ca..6b838c2b 100644 --- a/public/js/modules/TagDropdownColorizer.js +++ b/public/js/modules/TagDropdownColorizer.js @@ -72,7 +72,8 @@ export class GlpiPluginTagTagDropdownColorizer { }); $select.on('change select2:select select2:unselect', (event) => { - this.applyTagColors($(event.target)); + const $target = $(event.target); + setTimeout(() => this.applyTagColors($target), 0); }); $select.on('select2:open', () => { diff --git a/templates/dropdown.html.twig b/templates/dropdown.html.twig index 44220e5a..a888dfe5 100644 --- a/templates/dropdown.html.twig +++ b/templates/dropdown.html.twig @@ -39,17 +39,12 @@ 'values' : selected_tags, 'multiple': true, 'mb' : '', - 'add_data_attributes': { - 'glpi-plugin-tag-dropdown-uuid': rand + 'condition': condition, + 'specific_tags': { + 'data-glpi-plugin-tag-dropdown-uuid': rand } }|merge(dropdown_params|default({})) %} -{% set field %} - {% do call('Dropdown::showFromArray', [input_name, available_tags, { - 'value': null, - 'rand': rand, - }|merge(options)]) %} -{% endset %} {% set tooltip_parts = [] %} @@ -85,11 +80,15 @@ {% endif %} {% endif %} -{{ fields.field( +{{ fields.dropdownField( + 'PluginTagTag', input_name, - field ~ tooltip, + selected_tags, __('Tags', 'tag'), - options|merge({'id': 'dropdown_' ~ input_name|replace({'[': '_', ']': '_'}) ~ rand}) + options|merge({ + 'rand': rand, + 'add_field_html': tooltip, + }) ) }} + {{ fields.dropdownField( 'PluginTagTag', input_name, @@ -90,18 +132,6 @@ }) ) }} - - {% if show_save_button is defined and show_save_button %}