Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#814848
I am having an issue with summing the values in a grid in Form 1, formatting it to have a comma and then transferring it to Form 2. It's a little lengthy but I hope I conveyed my issue.

Form 1 contains a grid where a user can input the amount. The user wants the amount to display as 1,2345.21 (formatted with comma and decimal). Javascript exists to format the amount upon changing the form. The total appears in a separate field as the user wants Total to appear instead of the sum symbol. In order to sum the amounts, I format the amount for the Amount field, then un-format and place the number in a hidden field within the grid. I then sum the hidden fields, and format that to become the Total.

The problem is that when Form 2 is opened, even though the Total and Amount looks like the variable in Form 1 (1,2345.21), upon changing a drop down value, the Total re-sums itself with a new value, in this example 1 (it drops everything after the comma). Form 1 contains javascript to do the sum and format the numbers but Form 2 only contains javascript to show or hide fields depending on one of the other variables (Type - not associated with the amount/total).

I thought the variable value if used across multiple forms comes across with the same value. So why is the total changing when there is an update to the form 2? Thanks for the help.
#814852
Below is the code I'm using in Form 1. In the grid: 1=Amount and 9=Hidden Value.
Code: Select all
var formatDollar = new Intl.NumberFormat('en-US', {
  style: 'decimal',
  //style: 'currency',
  //currency: 'USD',
  minimumFractionDigits: 2,
});
//////////////////////////////
function formatNumber(vAmt,vId){  //
  if (vAmt.indexOf("$") == -1 ) {    
    if (vAmt.indexOf(",") != -1) {
      do {
        vAmt = vAmt.replace("," , "");
      } while (vAmt.indexOf(",") != -1);
    }
    $('#'+vId).setValue(formatDollar.format(vAmt));
  }
};
//////////////////////////////
var gridId = 'gridCoding'; //set to the ID of the grid
var sum =0;
function valGrid() {
  for (var i=1; i <= $('#'+gridId).getNumberRows(); i++) { 
    var gAmt =$('#'+gridId).getValue(i, 1);

    if (gAmt.indexOf("$") == -1 ) {
      if (gAmt.indexOf(",") != -1) {
        do {
          gAmt = gAmt.replace(",","");
        } while(gAmt.indexOf(",") != -1);
      }
      $('#'+gridId).setValue(formatDollar.format(gAmt),i,1);
    }   

    var newAmt = parseFloat(gAmt.replace(/,/g," "));
    $('#'+gridId).setValue(newAmt,i,9);
    
    if (gAmt > 0) {
      $("#form\\["+gridId+"\\]\\["+i+"\\]\\[gridAmount\\]").css("color", "black");
    }
    else {
      $("#form\\["+gridId+"\\]\\["+i+"\\]\\[gridAmount\\]").css("color", "red");
    }
  }  //end for loop
  calculateTotal();
};
//////////////////////////////
function calculateTotal() {
  var sum =0;
  for (var i=1; i<=$("#gridCoding").getNumberRows(); i++) { 
     sum = sum + (parseFloat($("#gridCoding").getValue(i, 9)));
  }
  var newSum = (parseFloat(Number(sum)).toFixed(2));
  var totalId = 'total'; //set to the ID of the total
  formatNumber(newSum, totalId);
};
//////////////////////////////
//execute when value in form changes:
$("form").setOnchange( function(fieldId, newVal, oldVal) {
  valGrid();
  var totalAmt = $("#totalAmount").getValue();
  var totalAmtId = 'totalAmount'; //set to the ID of the totalAmount
  formatNumber(totalAmt, totalAmtId);
});
#814865
When I re-tested this morning to get screen shots of the issue to go with the process, the total appears to be coming over with no issue. =( A little frustrated because I spent some time trying to figure out what was happening. Maybe a cache issue on the server? I did notice that on some occasions, the format used in Form 1 disappeared on Form 2 for the Amount values.
Attachments
(740.86 KiB) Downloaded 239 times
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[…]