I have a grid that is bound to a datasource. On the datasource if an error is returned on create my popup goes away and the new item stays in the grid (datasource). How do I either prevent the popup from going away and make the user cancel or try again, or remove the item if there is an error?
function getAntiForgeryToken() {
return $('input[name=__RequestVerificationToken]').val();
}
var viewModelNotes = kendo.observable({
notesDataSource: new kendo.data.DataSource({
transport: {
read: {
url: "/Vendor/GetVendorNotes",
dataType: "json",
data: {
VendorId: $("#Vendor_VendorId").val()
}
},
create: {
url: "/Vendor/CreateVendorNote",
dataType: "json",
type: "POST",
data: {
VendorId: $("#Vendor_VendorId").val(),
__RequestVerificationToken: getAntiForgeryToken()
}
}
},
schema: {
model: {
id: "VendorNoteId",
fields: {
VendorNoteId: { editable: false, nullable: true }
}
},
errors: "errorMsg"
},
pageSize: 20,
error: function (e) {
toastr.options = {
"positionClass": "toast-bottom-full-width"
};
toastr.error('Unable to save new note' + e.errors, 'Uh Oh!');
}
})
});
kendo.bind($('#VendorNoteWrapper'), viewModelNotes);
$("#VendorNotesGrid").kendoGrid({
dataSource: viewModelNotes.get("notesDataSource"),
scrollable: false,
toolbar: ["create"],
columns: [
{ field: "ItemText", title: "Note" },
{ field: "CreateDate", title: "Create Date" },
{ field: "CreatedByDisplay", title: "Created By" },
{ field: "LastModDate", title: "Modified" }],
editable: {
mode: "popup",
template: kendo.template($("#vendorNoteEditor").html())
}
});
function getAntiForgeryToken() {
return $('input[name=__RequestVerificationToken]').val();
}
var viewModelNotes = kendo.observable({
notesDataSource: new kendo.data.DataSource({
transport: {
read: {
url: "/Vendor/GetVendorNotes",
dataType: "json",
data: {
VendorId: $("#Vendor_VendorId").val()
}
},
create: {
url: "/Vendor/CreateVendorNote",
dataType: "json",
type: "POST",
data: {
VendorId: $("#Vendor_VendorId").val(),
__RequestVerificationToken: getAntiForgeryToken()
}
}
},
schema: {
model: {
id: "VendorNoteId",
fields: {
VendorNoteId: { editable: false, nullable: true }
}
},
errors: "errorMsg"
},
pageSize: 20,
error: function (e) {
toastr.options = {
"positionClass": "toast-bottom-full-width"
};
toastr.error('Unable to save new note' + e.errors, 'Uh Oh!');
}
})
});
kendo.bind($('#VendorNoteWrapper'), viewModelNotes);
$("#VendorNotesGrid").kendoGrid({
dataSource: viewModelNotes.get("notesDataSource"),
scrollable: false,
toolbar: ["create"],
columns: [
{ field: "ItemText", title: "Note" },
{ field: "CreateDate", title: "Create Date" },
{ field: "CreatedByDisplay", title: "Created By" },
{ field: "LastModDate", title: "Modified" }],
editable: {
mode: "popup",
template: kendo.template($("#vendorNoteEditor").html())
}
});