How to show error from JSON ?

3 posts, 0 answers
  1. Gert
    Gert avatar
    26 posts
    Member since:
    Jan 2015

    Posted 07 Feb 2015 Link to this post

    Hello,

    Wenn someone adds or modifies a task, the server checks if this is possible or not.
    ​At certain dates or times a task cannot created (holidays, already another task,....).
    ​The server/database  checks if this is possbile or not. if not I return a errormessage within a JSON.
    ​How do I show this errormessage to the user in de scheduler-popup window ?
     
  2. Gert
    Gert avatar
    26 posts
    Member since:
    Jan 2015

    Posted 10 Feb 2015 Link to this post

    Solved, Please remove this topic.
  3. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 10 Feb 2015 Link to this post

    Hello Gert,

    You can subscribe to the "error" event of the dataSource which is triggered either by HTTP error or if the response from the server contains field, described in the "dataSource.schema.errors" option. Then inside the "error" event handler you can notify the user for the server error and prevent the next "dataBinding" event of the scheduler - this way the edit window will remain open.

    e.g.:
    function error_handler(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
     
            var scheduler = $("#scheduler").data("kendoScheduler");
            scheduler.one("dataBinding", function (e) {
                //prevent saving if server error is thrown
                e.preventDefault();
            })
        }
    }



    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top