From fe5ddd3e1586c16d084d3562e6b7ec5141d47c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Farr=C3=A9?= <23310825+marc-farre@users.noreply.github.com> Date: Sat, 19 Apr 2025 23:13:03 +0100 Subject: [PATCH] Fix/7483 basepicker use itemkey instead of guid (#7498) * Fix #7483: BasePicker: when posting the form, use the itemKey value instead of the guid * Fix #7483: BasePicker: when posting the form, use the itemKey value instead of the guid * Restrict to id or guid * https://github.com/humhub/humhub/pull/7498#discussion_r2048892158 --- CHANGELOG.md | 1 + protected/humhub/modules/ui/form/widgets/BasePicker.php | 3 ++- static/js/humhub/humhub.ui.picker.js | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0197318ed4..d6e47c98eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ HumHub Changelog - Fix #7456: Fix setting manager backwards compatibility - Enh #7468: Remove deprecated widget `DataSaved` - Enh #7493: Add possibility to define content search order via module config +- Fix #7483: `BasePicker`: when posting the form, use the `itemKey` value instead of the `guid` 1.17.3 (Unreleased) ---------------------- diff --git a/protected/humhub/modules/ui/form/widgets/BasePicker.php b/protected/humhub/modules/ui/form/widgets/BasePicker.php index f2ed4f0bc5..678d3bd2fb 100644 --- a/protected/humhub/modules/ui/form/widgets/BasePicker.php +++ b/protected/humhub/modules/ui/form/widgets/BasePicker.php @@ -119,7 +119,7 @@ abstract class BasePicker extends JsInputWidget /** * The item key used as option value and loading items by attribute value. - * e.g. id or guid. + * Available values: `id` or `guid` * * @since v1.3 'id' by default * @@ -408,6 +408,7 @@ abstract class BasePicker extends JsInputWidget $result = [ 'add-options' => $this->addOptions, + 'item-key' => $this->itemKey, 'picker-url' => $this->getUrl(), 'picker-focus' => $this->focus, 'maximum-selection-length' => $this->maxSelection, diff --git a/static/js/humhub/humhub.ui.picker.js b/static/js/humhub/humhub.ui.picker.js index bb1e852094..b62eb64674 100644 --- a/static/js/humhub/humhub.ui.picker.js +++ b/static/js/humhub/humhub.ui.picker.js @@ -241,7 +241,7 @@ humhub.module('ui.picker', function (module, require, $) { item.disabled = true; } // Compatibility with old picker implementation and data attributes - item.id = item.guid || item.id || item['data-id']; + item.id = item.id || item.guid || item['data-id']; item.text = item.text || item.title || item.displayName || item['data-text']; item.image = item.image || item['data-image']; item.new = false; @@ -332,6 +332,10 @@ humhub.module('ui.picker', function (module, require, $) { }; Picker.prototype.prepareItem = function (item) { + const itemKey = this.$.data('item-key'); + if (itemKey && itemKey !== 'id' && item.hasOwnProperty(itemKey)) { + item.id = item[itemKey]; + } item.text = item.textValue || item.text || $(item.element).data('text'); item.image = item.image || $(item.element).data('image'); item.imageNode = this.getImageNode(item);