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

Update child without validation errors

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aldo
Top achievements
Rank 1
Aldo asked on 09 Dec 2014, 05:57 PM
Hi there,
I've a Scheduler and a Grid, i want to update the schedule when someone create or update the items in the grid.

I've subscribed the sync event with: .Events(events => events.Sync("sync"))

then I update the scheduler:

 function sync(args) {
        $("#scheduler").data("kendoScheduler").dataSource.read();
        $("#scheduler").data("kendoScheduler").refresh();
}

it works, but if there is a server validation error the editor popup quits and the user can't see the validation error.
How can I detect a successfully update?

Server validation is implemented as in the example provided:

<script type="text/kendo-template" id="message">
    <div class="k-widget k-tooltip k-tooltip-validation k-invalid-msg field-validation-error"
         style="margin: 0.5em; display: block; " data-for="#=field#" data-valmsg-for="#=field#" id="#=field#_validationMessage">
        <span class="k-icon k-warning"> </span>#=message#<div class="k-callout k-callout-n"></div>
    </div>
</script>


<script type="text/javascript">
    var validationMessageTmpl = kendo.template($("#message").html());

    function error(args) {
        if (args.errors) {
            var grid = $("#grid").data("kendoGrid");
            grid.one("dataBinding", function (e) {
                e.preventDefault();   // cancel grid rebind if error occurs

                for (var error in args.errors) {
                    alert(args.errors[error].errors);
                    showMessage(grid.editable.element, error, args.errors[error].errors);
                }
            });
        }
    }

    function showMessage(container, name, errors) {
        //add the validation message to the form
        container.find("[data-valmsg-for=" + name + "],[data-val-msg-for=" + name + "]")
                 .replaceWith(validationMessageTmpl({ field: name, message: errors[0] }))
    }

</script>



1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 11 Dec 2014, 02:30 PM
Hello,

In the sync event handler I can suggest to check if there are any pending changes in the dataSource e.g.
function sync(args) {
    if (!this.hasChanges()) {
        $("#scheduler").data("kendoScheduler").dataSource.read();
    }
}
If changes were correctly synchronized with the server then there should be any pending changes in the dataSource. An alternative would be to use the requestEnd event instead and check if there are any errors in the response.


Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Aldo
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or