lundi 6 novembre 2023

How to set Checkboxes for other tables to enabled if one table is true?

I have a table that is going through a validation with ajax, and the result returned is true, I have also set up a global flag where if the validation of that table is true, then the checkboxes for all the other tables should be enabled as well but for some reason its not working, and I dont know why. The table going through the validation is working 'tabCSite1' and 'tabCEquip1', where the checkboxes for it are enabled but for the other typetables its not working. Here is the code:

    function getDetailsCheckJob(data, typetable, checkboxname,t) {
    
    var tblC = document.getElementById(typetable);
    for (var i = tblC.rows.length - 1; i > 0; i--) {
        tblC.deleteRow(i);
    }

    Row = data.split('[');

    var tab = document.getElementById(typetable);
    var valid_asb = false;
    var valid_FTTH = false;
    var tabCSite1Valid = false;

    for (var p = 0; p < Row.length - 1; p++) {
        var row = tab.insertRow(p + 1);

        row.style.background = "#e8eef4";
        row.style.whiteSpace = "nowrap";

        splitData = Row[p + 1].split('|');
        

        if (splitData[0] == "Y") {
            row.insertCell(0);
            tab.rows[p + 1].cells[0].innerHTML = "<input type=\"checkbox\" id=\"valueZ\" name=\"" + checkboxname + "\" value=\"" + splitData[1] + "\" checked/>"; //checked
        }
        else if (splitData[0] == "N") {
            row.insertCell(0);
            tab.rows[p + 1].cells[0].innerHTML = "<input type=\"checkbox\" id=\"valueZ\" name=\"" + checkboxname + "\" value=\"" + splitData[1] + "\"/>";
        }
      
       if (typetable == "tabCEquip1") {
           checkValidation(splitData[2], splitData[28], splitData[29], t, jobID, function (resp) {

               valid_asb = resp.isASBExist;
               valid_FTTH = resp.isFTTHExist;
           });
        }

        else if (typetable == "tabCSite1") {

        checkValidation(splitData[2], splitData[23], splitData[29], t, jobID,function (resp) {
            valid_asb = resp.isASBExist;
            valid_FTTH = resp.isFTTHExist;
            tabCSite1Valid = valid_FTTH; // Update the global flag here
            console.log('tabCSite1Valid inside: ', tabCSite1Valid);
        });
        }

        var splitDatalen = splitData.length;

        if (typetable == "tabCEquip1" || typetable == "tabCSite1") {
            splitDatalen = splitDatalen - 3;
        }
        else {
            splitDatalen = splitDatalen - 1;
        }

        for (var i = 1; i < splitDatalen; i++) {

            console.log('tabCSite1Valid inside other one: ', tabCSite1Valid);
            //alert(splitData.length);
            row.insertCell(i);
            styleData = splitData[i + 1];
                if (typetable == "tabCEquip1" || typetable == "tabCSite1" || typetable == "tabCSBoundary1" || typetable == "tabLPcomm1" || typetable == "tabAddCardSplit1" || typetable == "tabDelEquip1" || typetable == "tabDelPath1" || typetable == "tabDelSB1" || typetable == "tabCPathConsumer1" || typetable == "tabCreateServiceOLT1") {
                    if (tabCSite1Valid == false) {
                        tab.rows[p + 1].cells[0].innerHTML = "<input type=\"checkbox\" id=\"valueZ\" name=\"" + checkboxname + "\" value=\"" + splitData[1] + "\" disabled/>";
                        styleData = "<span style='color: red'>" + splitData[i + 1] + "</span>";
                        console.log('Activated at FTTH');
                    }
                if (splitData[3] != "ASB" && valid_asb == true) { //else && valid_FTTH == false
                    tab.rows[p + 1].cells[0].innerHTML = "<input type=\"checkbox\" id=\"valueZ\" name=\"" + checkboxname + "\" value=\"" + splitData[1] + "\" disabled/>";
                    styleData = "<span style='color: red'>" + splitData[i + 1] + "</span>";
                    console.log('Activated at ASB');
                }
            }
            tab.rows[p + 1].cells[i].innerHTML = styleData;
        }
    }
}

The issue is the for loop for the last one, the 'tabCSite1Valid' is true for the tables tabCEquip1 and tabCSite1. I even set it to global and yet its still not being true for all the other tables. Where am I going wrong and how to fix it?

As can be seen in the picture, the checkbox is supposed to be enabled because the 'tabCSite1Valid' is true but instead its false

enter image description here




Aucun commentaire:

Enregistrer un commentaire