Grid Row Level cell to cell Validation Check in JavaScript

 

You cannot input a value greater than the needed value.

Step 1:
=====
At first, set the Static ID.
Grid Static ID: detailsid

Column Static ID: 

  • ALLOCATION_NEED
  • ALLOCATION_AMOUNT
Step 2:
=====

Create Dynamic Action On Page Load.
Action Name: Row Level New Allocation Check

Action: Execute JavaScript Code
Code: 

function validateAllocationAmount() {

    var amountInput = document.getElementById('ALLOCATION_AMOUNT');
    var needInput = document.getElementById('ALLOCATION_NEED');

    if (amountInput && needInput) {
        amountInput.addEventListener('change', function() {
            var amount = parseFloat(this.value) || 0;
            var need = parseFloat(needInput.value) || 0;            

            console.log("Direct Event - Amount:", amount, "Need:", need);            

            if (amount > need) {
                apex.message.alert("New Allocation cannot be greater than Allocation Need!");
                this.value = need;  //auto input actual need value
            }
        });

        console.log("✅ Allocation Amount validation attached successfully!");

    } else {
        console.log("⏳ Inputs not found, retrying...");

        setTimeout(validateAllocationAmount, 500);

    }
}

validateAllocationAmount();

Post a Comment

Previous Post Next Post