最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular + Dragula - Confirm on drop event - Stack Overflow

programmeradmin2浏览0评论

I would like to show a confirm modal dialog (UI Kit) when i drop an element in a new bag (I am using angular 1.4.8 and angular-dragula) . If I click ok, I want to continue the process, but if I click NO, i would like the element to e back to his origin bag.

This is my code so far :

dragulaService.options($scope, 'tasks', {
    revertOnSpill: true
});

$scope.$on('tasks.drop', function (e, el, target, source) {
    if (target[0].id == 'done') {
        UIkit.modal.confirm("Are you sure?", function(){
            console.log('drag confirmed');
        }, function(){
            // the function cancelling the drop...
        });
    } else {
        console.log('drag confirmed - no modal required');
    }
});

So far my dialog is showing perfectly, and if I click NO, the event is triggered, I just cant find how to cancel the drop ( I tried to find on dragula's documentation, but couldnt make it work.

Thank you.

I would like to show a confirm modal dialog (UI Kit) when i drop an element in a new bag (I am using angular 1.4.8 and angular-dragula) . If I click ok, I want to continue the process, but if I click NO, i would like the element to e back to his origin bag.

This is my code so far :

dragulaService.options($scope, 'tasks', {
    revertOnSpill: true
});

$scope.$on('tasks.drop', function (e, el, target, source) {
    if (target[0].id == 'done') {
        UIkit.modal.confirm("Are you sure?", function(){
            console.log('drag confirmed');
        }, function(){
            // the function cancelling the drop...
        });
    } else {
        console.log('drag confirmed - no modal required');
    }
});

So far my dialog is showing perfectly, and if I click NO, the event is triggered, I just cant find how to cancel the drop ( I tried to find on dragula's documentation, but couldnt make it work.

Thank you.

Share Improve this question edited Feb 20, 2016 at 23:18 Szabolcs Dézsi 8,84323 silver badges29 bronze badges asked Feb 20, 2016 at 20:18 NOaMTLNOaMTL 1931 gold badge4 silver badges14 bronze badges 1
  • 1 See github./bevacqua/dragula/issues/419 – leif.gruenwoldt Commented Nov 16, 2016 at 1:47
Add a ment  | 

1 Answer 1

Reset to default 5

I think you will have to do this manually, Dragula doesn't seem to provide a built-in mechanism for this. Once an item is dropped into the container, it is added to the DOM.

You will have to remove the element and put it back to the source container.

$scope.$on('tasks.drop', function (e, el, target, source) {
    if (target[0].id === "done" && source[0].id !== "done") {
        UIkit.modal.confirm("Are you sure?", function(){}, function(){
            $(el).remove();
            $(source).append(el);
        });
    }
});

I added the source[0].id !== "done" to prevent the modal popping up if you reorder items in the "Done" container.

Also note that this doesn't take the previous ordering of the source container into account. It just appends the element as the last element.

JSFiddle available here.

发布评论

评论列表(0)

  1. 暂无评论