search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

onEventMove - cancel on server error

Asked by Christos Georgiou
7 years ago.

I am trying to find a way to cancel the event upon error but with no luck.

I have the
onEventMove=function(args){
//an ajax call
}

But I don't know how to STOP the moved box from going to the moved position IF the ajax call returned an error

Answer posted by Dan Letecky [DayPilot]
7 years ago.

Christos,

Take a look at the "Asynchronous Validation" demo:
http://javascript.daypilot.org/demo/scheduler/asyncvalidation.html

    dp.onEventMove = function(args) {
        args.async = true;
        dp.message("Checking....");

        $.ajax({
            url: "asyncvalidation.txt",
            method: "GET",
            data: {
                dateFrom: args.newStart.toString(),
                dateTo: args.newEnd.toString(),
                id: args.e.id()
            }
        }).done(function (response) {
            var $response = $.parseJSON(response);

            if ($response.error) {
                dp.message($response.message);
                args.preventDefault();
            }
            args.loaded();
        });
    };

This code assumes the server returns a valid response (any server-side error will be returned using .error property in the response JSON). You can extend it easily for other types of server-side failure by adding .fail() handler to the $.ajax() call.

Note the key parts:
* Switch to async handling using args.async = true
* Cancel the action using args.preventDefault();
* Confirm the action using args.loaded();

Comment posted by Christos Georgiou
7 years ago.

Alright.. this seems to work but now I have another problem.

I have set blockOnCallBack = true
and my onEventMove = function(args) {

args.async = true;

if (!confirm('Are you sure you want to edit this?')) {
args.preventDefault();
args.loaded();
return;
}

// some code

}

The problem is that the ui is blocked even if I click on "cancel" on confirm box, like the args.loaded() not working properly

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.