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
This commit is contained in:
Marc Farré 2025-04-19 23:13:03 +01:00 committed by GitHub
parent 12d5df5b13
commit fe5ddd3e15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 2 deletions

View File

@ -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)
----------------------

View File

@ -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,

View File

@ -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);