I have a view in which I have a kendo-grid, in this grid there is a button to open a detail window. When the button is pressed the detail window opens which is a kendo-window which renders a partial view. When I close the kendo-window I destroy it and set it to null. However I have a JavaScript function on both my view and my partial view that catches the input of a scanner. If I scan while the window with the partial view is open the function on the view does nothing, however when I close the partial view the JavaScript function on the partial view still catches my scans and it tries to process the scan for both pages at once. How can I make sure the partial view is really closed so that it doesn't catch my scan input (preferably with JavaScript).
Partial view action method:
public ActionResult GetKendoWindow(int ID, int PID)
{
//fill and return partial view locationswindow
ViewBag.ID = ID;
ViewBag.PID = PID;
IEnumerable<BinLocationItemModel> model = dbLogic.getItemLocations(PID, ID);
return PartialView("_PartialViewLocation", model);
}
Kendo-window:
function showDetails(e) {
e.preventDefault();
if (wnd) {
wnd.close();
}
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
wndOpen = 1;
$("#detcont").append("<div id='Details'></div>");
wnd = $("#Details").kendoWindow({
width: "60%",
height: "60%",
actions: ["Minimize", "Maximize", "Close"],
title: "Location Data for: " + dataItem.ArticleID,
content: {
url: "GetKendoWindow",
type: "GET",
data: { ID: dataItem.LineNum, PID: dataItem.PickID }
},
close: function (e) {
wnd.destroy();
wnd = null;
setWindowInactive();
}
}).data("kendoWindow");
wnd.center().open();
}
function setWindowInactive(e) {
wndOpen = 0;
}
Partial View JS:
<script type="text/javascript">
//Scanner opvangen
$(document).ready(function () {
if ($('#ItemLocGrid') != null) {
var pressed = false;
var chars = [];
var grid = $('#ItemLocGrid').data('kendoGrid');
var dataitem = grid.dataItem(grid.select());
$(window).keypress(function (e) {
if (e.which >= 48 && e.which <= 57) {
if (chars.length < 3) {
// do nothing
} else {
$('.focus :input').focus();
}
chars.push(String.fromCharCode(e.which));
}
if (pressed == false) {
setTimeout(function () {
if (chars.length >= 5) {
var barcode = chars.join("");
document.getElementById("txtBarcodes").value = barcode;
$('.focus :input').submit();
}
chars = [];
pressed = false;
document.getElementById("txtBarcodes").value = "";
}, 200);
}
pressed = true;
});
}
});
$('#txtBarcodes').submit(function (e) {
var grid = $("#ItemLocGrid").data("kendoGrid");
var dataSource = $("#ItemLocGrid").data("kendoGrid").dataSource;
var allData = grid.dataSource.data();
var code = this.value;
var notification = $("#notification").data("kendoNotification");
console.log("Nothing to see here");
})
It wasn't exactly like SeM mentioned but his code gave me the idea which fixed it. What I did was put my JavaScript code from my partial view into my view(instead of the layout), I didn't realize my view would be able to read a kendo-grid without actually containing it in its code but it actually can. After that it was just a matter of checking if the window is open and processing a scan for either the partial view or the view.