Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#829595
Hi,

I need to
1) disable some of the cells in a row of the grid when the <trash> button of the row is clicked, and
2) hide the <trash> button
in a dynaform.
The enclosed javascript program is written for such purpose.

My problem is when the <trash> button is clicked, not only the cells to be disabled CANNOT be disabled, but also ALL the disabled cells in the dynaform are enabled!

I have tested with disabling either the hide <trash> button statement or the for loop on disabling cells, the same problem presist disregard of which statement I disabled.

Grateful if I can have your advice in fixing the bug.

Thousand Thanks.

cheers,
Karl


// -------- javascript to disable some grid cells instead of delete row on <trash> button is clicked --------

function onDelRow(e) {
var rowNo = $(this).attr("data-row");
var gdIdThisNm = e.data.param1;
var ColNoLst = e.data.param2;
var jgd = $('#'+gdIdThisNm);

// // --- hide <del>
$(jgd.find("div.pmdynaform-grid-row")[rowNo-1]).find("button").hide();

// // disable fields
for (i in ColNoLst){
jgd.getControl(rowNo, ColNoLst).attr("disabled", true);
}; // end for

}; // end onDelRow(e)

// ---- gdOnLoad ------

function gdOnLoad(gdId, ColNoDisableLst){
var jgd = $('#' + gdId);
var gdLen = jgd.getNumberRows();
ColNoLst = ColNoDisableLst;

if (gdLen > 0){
//turn off the click event handler for "Delete" button in all existing grid rows when Dynaform loads
//subtract because eq() starts counting from 0, not 1 like rowIndex:
jgd.find("button.glyphicon-trash").off("click");

//add custom click event handler for delete buttons in grid when Dynaform loads:
jgd.find("button.glyphicon-trash").click({param1: gdId, param2: ColNoLst}, onDelRow);

}; // end if not zero row
}; // end gdOnLoad


// --- gdOnAddRow ------
function gdOnAddRow(gdId, rowIndex, ColNoDisableLst){
var jgd = $('#' + gdId);
ColNoLst = ColNoDisableLst;

//subtract because eq() starts counting from 0, not 1 like rowIndex:
jgd.find("button.glyphicon-trash").eq(rowIndex-1).off("click");
jgd.find("button.glyphicon-trash").eq(rowIndex-1).click({param1: gdId, param2: ColNoLst}, onDelRow);
// jgd.find("button.glyphicon-trash").click(onDelRow2(gdId, ColNoLst, rowIndex));
}; // end gdOnAddRow

// --- grid parameters initialization
var formId = $("form").prop("id");


// --- grid gdCltLst ---
var gdCltLstId = "clientsList" ;
var jgdCltLst = $("#"+gdCltLstId);
var gdCltDisableColNoLst = [1,3]; // columns to be disabled

// // -- gdCltLst onLoad ----
gdOnLoad(gdCltLstId, gdCltDisableColNoLst);

// // --- gdCltLst onAddRow ----
jgdCltLst.onAddRow(function(aNewRow, oGrid, rowIndex){
gdOnAddRow(gdCltLstId, rowIndex, gdCltDisableColNoLst);
});

// --- grid gdT1 ---
var gdT1Id = "gdT1" ;
var jgdT1 = $("#"+gdT1Id);
var gdT1DisableColNoLst = [2,4]; // columns to be disabled

// // -- gdT1 onLoad ----
gdOnLoad(gdT1Id, gdT1DisableColNoLst);

// // --- gdT1 onAddRow ----
jgdT1.onAddRow(function(aNewRow, oGrid, rowIndex){
gdOnAddRow(gdT1Id, rowIndex, gdT1DisableColNoLst);
});
#829596
Hi Karl,
I rushed to read through your code, I just spot out :
Code: Select all
//1. // --- hide <del>
$(jgd.find("div.pmdynaform-grid-row")[rowNo-1]).find("button").hide();

//you should try: //hide the trash only 
$(jgd.find("div.pmdynaform-grid-row")[rowNo-1]).find("button.glyphicon-trash").hide();

//2. // // disable fields
for (i in ColNoLst){
jgd.getControl(rowNo, ColNoLst).attr("disabled", true);
}; // end for

// you should try:              //if ColNoLst = [1,3,5]                    
// for..in = loop over object property name;           for..of = loop over arrays or strings
for (const i in ColNoLst){
jgd.getControl(rowNo, ColNoLst[i]).attr("disabled", true);
}; // end for
//OR also try:
for (const colNo of ColNoLst){
jgd.getControl(rowNo, colNo).attr("disabled", true);
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]