Skip to content

JS Function: __postvalid

Description: Executes post-validation (triggered typically onBlur or when the field loses focus) on a specific field of a table. The table can either be a Form table or a Grid table. This is commonly used in Merciglobal Cloud ERP to ensure data integrity by recalculating or verifying values immediately after user input.


Usage

To be defined in project_core.js

function trn_yarnschlg_rate_postvalid(hotrow, hotcol, colname, oldval, newval){
    let rate = parseFloat(eval(newval)); // force convert the newval to float
    let qty = grid1.getDataAtCell(hotrow, gridColNum('qty')); // fetch value from a cell, here Qty
    let amt = (rate * qty).toFixed(2); // calculate amount, limited to 2 decimals

    // set the calculated amount in the 'amount' column. 
    // 'AUTOSET' avoids executing post validations on this auto-set value.
    grid1.setDataAtCell(hotrow, gridColNum('amount'), amt, 'AUTOSET');
}

Parameters

Name Type Description
hotrow number Current grid row number
hotcol number Current grid column number
colname string Current grid column field name
oldval any Existing value before the field was edited
newval any New value after the field was edited

Return

  • Nothing: This function does not return a value but updates related fields directly within the grid.

Application in Merciglobal Cloud ERP

This function type is integral in modules like Sales, Purchase, and Inventory where real-time calculations (like Amount = Rate * Quantity) are crucial for accuracy. By automatically updating dependent fields, it reduces manual errors and ensures seamless data coherence across forms and tables.


Best Practices

  • Use eval(newval) cautiously; consider sanitizing inputs to avoid malicious scripts.
  • Always validate the existence of dependent fields (qty, amount) before applying logic.
  • Avoid triggering recursive validations by utilizing flags like 'AUTOSET'.