Skip to content

Commit

Permalink
IBX-9322: ezobjectrelationlist field allows selecting the same conten…
Browse files Browse the repository at this point in the history
…t multiple times
  • Loading branch information
lucasOsti committed Dec 13, 2024
1 parent 843ac71 commit ce73425
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@
sourceInput.dispatchEvent(new CustomEvent(EVENT_CUSTOM));
};
const onConfirm = (items) => {
items = excludeDuplicatedItems(items);
const itemsWithoutDuplicate = excludeDuplicatedItems(items);

renderRows(items);
renderRows(itemsWithoutDuplicate);
attachRowsEventHandlers();

selectedItems = [...selectedItems, ...items.map((item) => item.ContentInfo.Content._id)];
selectedItems = [...selectedItems, ...itemsWithoutDuplicate.map((item) => item.ContentInfo.Content._id)];

updateInputValue(selectedItems);
closeUDW();
Expand Down Expand Up @@ -157,11 +157,7 @@
}),
);
};
const excludeDuplicatedItems = (items) => {
selectedItemsMap = items.reduce((total, item) => ({ ...total, [item.ContentInfo.Content._id]: item }), selectedItemsMap);

return items.filter((item) => selectedItemsMap[item.ContentInfo.Content._id]);
};
const excludeDuplicatedItems = (items) => items.filter((item) => !selectedItems.includes(item.ContentInfo.Content._id));
const renderRow = (item, index) => {
const { escapeHTML } = ibexa.helpers.text;
const { formatShortDateTime } = ibexa.helpers.timezone;
Expand Down Expand Up @@ -304,7 +300,6 @@
updateInputValue(selectedItems);
};
let selectedItems = [...fieldContainer.querySelectorAll(SELECTOR_ROW)].map((row) => parseInt(row.dataset.contentId, 10));
let selectedItemsMap = selectedItems.reduce((total, item) => ({ ...total, [item]: item }), {});

updateAddBtnState();
attachRowsEventHandlers();
Expand Down

0 comments on commit ce73425

Please sign in to comment.