This is a migrated thread and some comments may be shown as answers.

Disabling Drag and Drop

6 Answers 426 Views
Drag and Drop
This is a migrated thread and some comments may be shown as answers.
Joao
Top achievements
Rank 1
Joao asked on 19 Oct 2011, 10:13 PM
How do I disable dragging after the draggable hits its target?

6 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 20 Oct 2011, 08:31 AM
Hello Joao,

First, let me clarify your question. Do you mean

"How do I prevent subsequent dragging of the same draggable object after it has been dropped over the expected drop target?"

If this is what you mean, you can use a global Javascript variable as a flag and set it in the OnDrop event. Here is a demo based on this example:

http://demos.kendoui.com/dragdrop/events.html

var globalFlag = false;
 
function draggableOnDragStart(e) {
    if (globalFlag) {
        e.preventDefault();
        return false;
    }
}
 
function droptargetOnDrop(e) {
    globalFlag = true;
}


Best wishes,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dmitriy
Top achievements
Rank 1
answered on 02 Apr 2012, 11:32 AM
$(draggable).off();
0
Eric
Top achievements
Rank 2
answered on 14 Sep 2012, 12:28 PM
I would like more information on this...

The proposed solution will not work for me. I want to destroy the draggable object so that all of the drag events registered with the elements specified by my jQuery selector when creating the draggable object(s) are removed.

I have attempted to call the .destroy() method on the draggable object(s), but to no avail, I am still able to drag the elements post my call to .destroy().

The suggestion offered by Dmitriy will not work for me because there are other event handlers register with the elements in question.

Any assistance/guidance would be appreciated.
0
Nohinn
Top achievements
Rank 1
answered on 14 Sep 2012, 01:53 PM
To delete everything related to drag & drop:
$('#draggable').removeData('kendoDraggable');
$('#draggable').removeData('role');
$('#draggable').unbind('mousedown');
$('#draggable').unbind('selectstart');

Though, as you can see it may turn out to be a bit more complex if you have assigned too a mousedown handler or a selectstart handler.
Right now that handler would be also deleted, so your app may stop working as it should.
0
Eric
Top achievements
Rank 2
answered on 14 Sep 2012, 02:33 PM
Thank you for your response Nohinn, i will give your suggestion a try; however, i do have other handlers specified for mouse down (one of the reasons why a call to .off() wouldn't work for me) so it may still be a no go. I suppose when registering the other event handlers I could namespace them and use that to exclude them from being unbound...

Do you have any idea why a call to .destroy() wouldn't do this for me Nohinn, or have I missed the point of the .destroy() method altogether?

Either way it seems odd that this ability is not built into the draggable object... any of the Telerik folks out there have any idea when a means to do this through the draggable API might be available in the control suite?
0
Nohinn
Top achievements
Rank 1
answered on 14 Sep 2012, 02:49 PM
It looks like the destroy method for the drag & drop feature would just delete events owned by the kendoDraggable widget, those are:
  • drag
  • dragcancel
  • dragend
  • dragstart
It also removes the keyup event handler, but I think they do nothing about the mousedown and selectstart event applied to the dom element.
Tags
Drag and Drop
Asked by
Joao
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Dmitriy
Top achievements
Rank 1
Eric
Top achievements
Rank 2
Nohinn
Top achievements
Rank 1
Share this question
or