admin管理员组文章数量:1024945
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
1 Answer
Reset to default 5I 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.
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
1 Answer
Reset to default 5I 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.
本文标签: javascriptAngularDragulaConfirm on drop eventStack Overflow
版权声明:本文标题:javascript - Angular + Dragula - Confirm on drop event - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745618372a2159426.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论