Jesus A. Jesus A. - 19 days ago 5
Javascript Question

How validation works

I´m supporting API where I need to update validation into javascript method:

function AddCategory() {
var category = $("#category");
var subCategory = $("#subcategory");

if (category.val().length > 0 && subCategory.val().length > 0) {
var grid = $("#lstCategory").data("kendoGrid");
var listGrid = $("#lstCategory").data().kendoGrid.dataSource.data();

var dataS = grid.dataSource;

if (!FindObjectInList(listGrid, "idSubcategory", subCategory.val())) {
dataS.add({
idCategory: category.val(),
category: $("option:selected", category).text(),
idSubcategory: subCategory.val(),
subCategory: $("option:selected", subCategory).text()
});

dataS.sync();
}
else {
InfoMessage("Category", "Selected subcategory cannot add again");
}
} else {
WarningMessage("Warning", "Select category and subcategory...");
}
}


I need to remove this validation:

InfoMessage("Category", "Selected subcategory cannot add again");


But I don´t understand how this method works, anyone can explain me it? Regards

Answer

How it works:

First, pass listGrid, idSubcategory and the value returned from subCategory.val() into FindObjectInList. If null is returned (the category does not exist) - then add the new category information passed in. Else, if the function returns true (the category already exists) then serve up the notification to the user via the InfoMessage function.

 if (!FindObjectInList(listGrid, "idSubcategory", subCategory.val())) {
        dataS.add({
            idCategory: category.val(),
            category: $("option:selected", category).text(),
            idSubcategory: subCategory.val(),
            subCategory: $("option:selected", subCategory).text()
        });

      dataS.sync();
    }
    else {
        InfoMessage("Category", "Selected subcategory cannot add again");
Comments