I'm using this knockout binding to add html5 drag and drop to my application.
https://github.com/bramstein/knockout.dragdrop
I have two observable arrays with items that can be dragged between them.
On page load all the items in both lists are draggable and work as expected.
The problem occurs when I try to drag items back to their original list, the drag and drop stops working.
As you can see from my console.log, I have dragged and held the element for a few seconds and then dropped it into list 2.
When I try and drag that same element back to list 1, the drag start and drag end triggers instantly.
- dragStart - 13:24:54
- dragEnd - 13:24:56
- dragStart - 13:25:0
- dragEnd - 13:25:0
Below is my data-bind for list 1
<ul data-bind="
dropzone: { name: 'unassigned', drop: $root.DropUnassignedStandard }">
<!-- ko foreach: DupeStandards -->
<li data-bind="text: Name,
dragzone: { name: 'assigned', dragStart: $root.onStart, dragEnd: $root.onEnd }" draggable="true" />
<!-- /ko -->
</ul>
Below is my data bind for list 2
<div data-bind="
dropzone: { name: 'assigned', drop: $root.DropAssignedStandard }">
<ul>
<!-- ko foreach: UnassignedDupeStandards -->
<li data-bind="text: Name,
dragzone: { name: 'unassigned', dragStart: $root.onStart, dragEnd: $root.onEnd }" draggable="true" />
<!-- /ko -->
</ul>
</div>
Below is my onStart function
self.onStart = function (data) {
var currentDate = new Date();
var datetime = currentDate.getHours() + ":"
+ currentDate.getMinutes() + ":"
+ currentDate.getSeconds();
console.log('dragStart - ' + datetime);
}
Below is my onEnd function
self.onEnd = function (data) {
var currentDate = new Date();
var datetime = currentDate.getHours() + ":"
+ currentDate.getMinutes() + ":"
+ currentDate.getSeconds();
console.log('dragEnd - ' + datetime);
}
Below is the function to move items from list 1 to list 2
self.DropAssignedStandard = function (droppedStandard) {
self.UnassignedDupeStandards.push(droppedStandard);
var user = ko.utils.arrayFirst(self.Users(),
function (user) {
return ko.utils.arrayFirst(user.DupeStandards(),
function (ds) {
return ds.DupeStandardID === droppedStandard.DupeStandardID;
});
});
user.RemoveStandard(droppedStandard);
}
Below is the function to move items from list 2 to list 1
self.DropUnassignedStandard = function (droppedStandard, user) {
user.AddStandard(droppedStandard);
self.UnassignedDupeStandards.remove(droppedStandard);
}
Any help is appreciated, thanks.