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

[Solved] Prevent node drop after verifiying using Ajax call.

2 Answers 79 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rakesh
Top achievements
Rank 1
Rakesh asked on 10 Apr 2012, 02:49 PM
I need to verify the drop is valid or not using ajax call and if it is not valid drop i need to prevent.

Even if my ajax call return false i cant able to stop from dropping. Please help me to fix this issue ASAP.

here is my code

function onNodeDrop(e) {
        var treeview = $('#TreeView').data('tTreeView');
        var nodeText = treeview.getItemText(e.item);
        var nodeValue = treeview.getItemValue(e.item);
        var dropNodeText = treeview.getItemText(e.destinationItem);
        var dropNodeValue = treeview.getItemValue(e.destinationItem);
        var ManageCategory = { SourseNodeText: nodeText, SourceNodeValue: nodeValue, DestinationNodeText: dropNodeText,           DestinationNodeValue: dropNodeValue };
        $.ajax({
            url: '@Url.Action("Manage", "GroupsAndEvents")',
            data: ManageCategory,
            type: 'POST',
            contentType: 'application/x-www-form-urlencoded',
            success: function (data) {
                       if (data.Status == false) {                  // Its coming inside of this if block but its not working
                                    e.preventDefault();
                       }
            }
            });
}

2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 13 Apr 2012, 06:41 AM
Hi Rakesh,

Since the success function of your Ajax request is an asynchronous one you cannot call preventDefault() inside of it.
What you can do instead is to always call e.preventDefault, but save the e.destinationItem and the e.item to a local variables. This way when your Ajax request success function is called you can use the append method and the saved local variables to perform the append.


Greetings,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
RES
Top achievements
Rank 1
answered on 13 Apr 2012, 11:58 PM
Or you can just set async to false.
Tags
TreeView
Asked by
Rakesh
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
RES
Top achievements
Rank 1
Share this question
or