Discussion about developing the ProcessMaker application and suggestions for improving it

Moderator: ArturoRobles

By kleung
#829118
Hi,

Grateful if I can receive some help.

I have a dynaform which consists of 4 different grids and some other fields. Onchange of different cells in different grids would lead to different computations in the grids / form.

My problems is how can I know which cell (rowNo, colNo) in which grid is changed and the new value as well.
The method $("#form\\[gridId\\]\\[rowNumber\\]\\[fieldId\\]").change( function() { //event handler code } ); in https://wiki.processmaker.com/3.0/Grid_Control#Change_events_in_grids handle one column at a time. But in my case, I need to monitor the changes of 2-3 columns in each grid. This method is very clumsy. Any simpler method?

I'm using PM 3.2 community version.

Thousand Thanks.

cheers,
karl
User avatar
By kirkwg
#829121
Hi,

This is common usage to check or monitor fields get changed by form.setOnchange(), examples see the doc
https://wiki.processmaker.com/3.2/JavaScript_Functions_and_Methods/Dynaforms
similar to grid fields as well..
one e.g. in the link:
Code: Select all
var formId = $("form").prop("id"); //get Dynaform's ID  

//first event handler which will never executed:
$("#"+formId).setOnchange( function(fieldId, newVal, oldVal) {
   //always capitalize account name:
   if (fieldId == 'accountName') {
      $("#"+fieldId).setValue( newVal.toUpperCase() );
   }
});

//This second event handler will overwrite the first event handler:
$("#"+formId).setOnchange( function(fieldId, newVal, oldVal) {
   if (fieldId == 'taxRate' || fieldId == 'price') {
      var  subtotal = parseFloat( $("#price").getValue() ) * parseFloat( $("#taxRate").getValue() );
      $("#amount").setValue(subtotal);
   }
});
User avatar
By kirkwg
#829122
Another example to monitor a grid field below:
var aMatches = fieldId.match(/^\[receiptGrid\]\[(\d+)\]\[receiptItem\]$/); //e.g. monitor a grid field id=receiptItem
or use var aMatches = fieldId.match(/^\[receiptGrid\]\[(\d+)\]\[(\w+)\]$/); // \w+ means monitoring any fields in this grid
aMatches[0] will return the grid_id
aMatches[1] will return the grid row happened, start from row 1, row 2, etc.
aMatches[2] will return the field_id of the grid
Code: Select all
//========== JS disable validation on a particular field inside a grid on a particular row
$( "#" + $("form").prop("id") ).setOnchange( function( fieldId, newValue, oldValue ) {
   var aMatches = fieldId.match(/^\[receiptGrid\]\[(\d+)\]\[receiptItem\]$/);
  
   if (aMatches) {    
     var rowNo       = aMatches[1];
     var gridFieldId = aMatches[2];
     var gridId         = "receiptGrid";
     var checkedVal = "stock";
     if (newValue === checkedVal) {     	
        getFieldById(gridId).gridtable[rowNo-1][2].disableValidation();
     } else 
        getFieldById(gridId).gridtable[rowNo-1][2].enableValidation();     
   }
});

I am trying to assign to a group of users by passi[…]

Hi, Are you sure you want to ask this? ^^ You pr[…]

PMDynaform is undefined

You are super!.... ^^

Thank you for providing this quick guide. It is re[…]