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

dataSource error management

4 Answers 1885 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 2
Iron
Jack asked on 28 Nov 2014, 02:31 PM
I have implemented a feature similarly to http://demos.telerik.com/kendo-ui/listview/mvvm except:
1) the create transport is implemented;
2) all transports are functions calling $.ajax with specific options.

The server validates data and I could certainly match validation rules on the client, but I am not there yet.

At this stage, a creation or an update made with invalid data triggers a 400 - Bad Request response from the server.

The issue I have, is the error as no effect on the listView:
- the creation is validated with invalid data (it looks this way)
- the update is also validated with invalid data (it also looks this way).
When I would have expected the listView to remain in edit mode with a validation error message (like with client validation).

Is this normal behavior and is it up to the programmer to define the consequences of an error?

To achieve this, I have bound the error event of the dataSource to an event handler and I get the xhr, the status and the errorThrown. Unfortunately the event handler does not tell me which transport went wrong (creation, update) and which item is affected. Is there any way to obtain these informations to restore the listView in edit mode and display a validation error message?








4 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 02 Dec 2014, 12:40 PM
Hello Jack,

Indeed, the developer should implement the behavior on the error himself by using the error event. However, in order to keep the edit form open, you may use the ListView save event and call the sync method by hand.

var dataSource = new kendo.data.DataSource({
    transport: {
        /*..*/
    },
    error: function(e) {
        //TODO: handle the errors
        alert(e.errorThrown);
    },
    /*..*/
});
 
$("#listView").kendoListView({
    dataSource: dataSource,
    save: function(e) {
        //prevent form from closing
        e.preventDefault();
        //push the changes to the server
        this.dataSource.sync();
    },
    /*..*/
});


Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jack
Top achievements
Rank 2
Iron
answered on 02 Dec 2014, 06:10 PM
Doing as suggested calls transport methods twice, despite having data-auto-bind="false". Any ideas?
0
Jack
Top achievements
Rank 2
Iron
answered on 02 Dec 2014, 06:26 PM
Also e.preventDefault() does not prevent the listView edit form (editTemplate) to close and be replaced by the standard form (template) although I have checked with a debugger that the line is hit.

listView.bind('save', function(e) {
    viewModel.comments.sync()
        .fail(function() {
            e.preventDefault();
        });
});
0
Jack
Top achievements
Rank 2
Iron
answered on 02 Dec 2014, 06:44 PM
Sorry for the confusion, Rosen,
e.preventDefault() in the callback is stupid.
I have rerun your suggestions and it works perfectly.
Not sure what was going wrong in the first time.
Tags
Data Source
Asked by
Jack
Top achievements
Rank 2
Iron
Answers by
Rosen
Telerik team
Jack
Top achievements
Rank 2
Iron
Share this question
or