From b97188a3a1e39e9c386bf2b02b6ba0c64ef2df77 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Thu, 6 Jun 2024 12:27:57 +0200 Subject: [PATCH 1/2] Fix programmatically removing a list item --- scripts/h5peditor-list-editor.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/h5peditor-list-editor.js b/scripts/h5peditor-list-editor.js index dfaf455c..0816ef8e 100644 --- a/scripts/h5peditor-list-editor.js +++ b/scripts/h5peditor-list-editor.js @@ -704,15 +704,18 @@ H5PEditor.ListEditor = (function ($) { 'remove', H5PEditor.t('core', 'removeItem'), function () { confirmHandler(item, $item.index(), $(this).offset(), function () { list.removeItem($item.index()); - $item.remove(); - - if (!(list.getValue() ?? []).length) { - self.removeCollapseButtons(); - } }); } ).appendTo($listActions); + list.on('removedItem', (event) => { + $item.remove(); + + if (!(list.getValue() ?? []).length) { + self.removeCollapseButtons(); + } + }); + // Append new field item to content wrapper if (item instanceof H5PEditor.Group) { // Append to item From cc51fff7b239910e295714ba1382c6740c180de2 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Fri, 10 Jan 2025 10:10:16 +0100 Subject: [PATCH 2/2] Fix item DOM removal --- scripts/h5peditor-list-editor.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/h5peditor-list-editor.js b/scripts/h5peditor-list-editor.js index 0816ef8e..6b371a3c 100644 --- a/scripts/h5peditor-list-editor.js +++ b/scripts/h5peditor-list-editor.js @@ -709,6 +709,10 @@ H5PEditor.ListEditor = (function ($) { ).appendTo($listActions); list.on('removedItem', (event) => { + if (event.data !== $item.index()) { + return; + } + $item.remove(); if (!(list.getValue() ?? []).length) {