From 370c6dce3ed6f3c5ca0c48a40781b46ce42351b8 Mon Sep 17 00:00:00 2001 From: quang phan Date: Mon, 20 May 2019 17:59:11 +0700 Subject: [PATCH] Fix issue items are always cloned --- knockout-sortable.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/knockout-sortable.js b/knockout-sortable.js index fedcff7..16351cf 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -119,6 +119,8 @@ var removeOperation = currentOperation.event.type === 'remove' ? currentOperation : existingOperation, addOperation = currentOperation.event.type === 'add' ? currentOperation : existingOperation; + addOperation.event.groupOption = parentBindings.sortable.options.group; + moveItem(itemVM, removeOperation.collection, addOperation.collection, addOperation.event.clone, addOperation.event); } }, @@ -151,7 +153,13 @@ fromArray.splice(originalIndex, 1); // Update the array, this will also remove sortables "unbound" clone from.valueHasMutated(); - if (clone && from !== to) { + + var groupOption = e.groupOption; + // See the option at https://github.com/SortableJS/Sortable#options + // group: { name: 'shared', pull: 'clone' } + var cloneable = typeof groupOption === 'object' && groupOption.pull === 'clone'; + + if (cloneable && clone && from !== to) { // Read the item fromArray.splice(originalIndex, 0, itemVM); // Force knockout to update