I have a popup that contains kendoDropdownlists,and when I go to edit a selected record, for some reason it makes its own mind up whether a dropdown is going to be populated and have an item in it preselected. The steps that are taken is...
1) I navigate to a view that holds a grid and that grid contains partial records of information of materials and contains a checkbox in each row
2) I select a checkbox and click an edit button
3) Selected ID gets put into storage and a popup with a form in it opens up
4) The ID in the storage is used to get the selected material's information and is to populate the form fields and dropdowns.
5) Sometimes the dropdowns don't populate and throw this error
VM752:250 Uncaught TypeError: Caot read property 'value' of undefined
MaterialUpdateData @ VM752:250
success @ VM752:278
c @ jquery-1.10.2.min.js:21
fireWith @ jquery-1.10.2.min.js:21
k @ jquery-1.10.2.min.js:23
r @ jquery-1.10.2.min.js:23
and I know that there is data because I debug in chrome and have a console log that shows the data and its all correct, and I have also double checked my SQL data
here is my document on load
$(document).ready(function () {
// Validation
MaterialValidation();
// Loading of dropdownlists
LoadCategoryDropdownlist();
LoadTypeDropdownlist();
//LoadSubTypeDropdownlist(1);
LoadActiveVendorDropdownlist();
GlobalScript.GetAllUOM("BuyUOM");
GlobalScript.GetAllUOM("SellUOM");
if (HomeStorage.Keys.AddOrEdit == "Add") {
console.log("Add");
}
else {
GetMaterialDataByID(HomeStorage.Keys.CurrentID);
}
});
here is my GetMaterialDataByID function
function GetMaterialDataByID(id) {
$.ajax({
type: "GET",
url: URLParam.GetMaterialForUpdate + "?id=" + id,
contentType: "application/json; charset=utf-8",
success: function (data, textStatus, jqXHR) {
MaterialUpdateData(data);
}
})
}
and here is my MaterialUpdateData function
function MaterialUpdateData(Material) {
console.log(Material);
var a = $("#Category").data("kendoDropDownList");
a.value(Material[0].MaterialCategoryID);
var b = $("#Type").data("kendoDropDownList");
b.value(Material[0].MaterialTypeID);
//var c = $("#SubType").data("kendoDropDownList");
//c.value(Material[0].MaterialSubTypeID);
var d = $("#ddBuyUOM").data("kendoDropDownList");
d.value(Material[0].PurchaseUOMID);
var e = $("#ddSellUOM").data("kendoDropDownList");
e.value(Material[0].SellUOMID);
var f = $("#DefaultVendor").data("kendoDropDownList");
f.value(Material[0].VendorID);
$("#txtDescription").val(Material[0].Description);
$("#txtWidth").val(Material[0].DWidth);
$("#txtLength").val(Material[0].DLength);
$("#txtSize").val(Material[0].DHeight);
$("#txtRemodel").val(Material[0].RemodelPrice);
$("#txtRemodel1").val(Material[0].ServicePrice);
$("#txtPurchaseQuantity").val(Material[0].PurchaseItemQuantity);
$("#txtSellQuantity").val(Material[0].SellItemQuantity);
}
That error can be thrown on any of the var a, b, c, d, e, f
Yes I know that I have a c commented out.
Anyhow sometimes the dropdowns get properly set and sometimes they don't and as of late, I only get a couple that will be properly set and then an error is thrown on any of them and then the other fields won't populate because of the error.
Is there any reason why this is happening or maybe I have placed everything in the wrong area, what am I missing here?
