You are viewing limited content. For full access, please sign in.

Question

Question

Calculation JS Help

asked on September 1, 2016 Show version history

Having an odd behavior with a form and calculating totals and were wondering if anyone can offer a little help.  

We have a table that gets populated by a stored procedure.  The users access the Form by clicking a link.  In the URL is the variable needed so the page loads with the variable in place, the procedure happens, and the table is populated.  This works great.

However, we have a Total Verified Asset Balance field (number field) that holds the total of all the Verified Balance columns.    When we have nothing in the verified balance columns it is showing 0, not nothing.  For this process, empty means the verification has not happened yet.  0 means that the assets could be 0 so there is a difference.  

Also, when we hit our Add button for the table,   it immediately puts a 3.  It's as if it is seeing the rows as the values.   

If we do put totals in it is not correct:

Finally, if we submit that form and then go back to it the stored procedure runs and indeed returns the correct balances, but the total then shows nothing (seems that the JS does not see them?)

We cannot use Forms calculations due to bugs when removing all rows (current filed SCR, not sure about when it will be released).

Below is the code we have.  Any help would be appreciated.

function sumtotal() {
  var sum = 0;
  $('td.asset').each(function () {
    var s = 0;
    $(this).find('input').each(function () { s += parseNumber($(this).val()); })
    sum += s;
  });
  $('.total input').val(sum);
}

function parseNumber(n) {
  var f = parseFloat(n);   //Convert to float number.
  return isNaN(f) ? 0 : f; //treat invalid input as 0;
}

 

0 0

Replies

replied on September 1, 2016

The issue seems to be related with other code that you didn't post here. Can you post the entire script? And can you show which field has the 'asset' class?

As for the deleting rows bug, if you mean https://answers.laserfiche.com/questions/88239/Does-SUM-calculations-only-trigger-on-clicking-the-add-button then it has been resolved by a hotfix (inside the link).

0 0
replied on September 2, 2016 Show version history

The bug we had was when removing all the rows.  The form acts as an edit and the user can delete all the rows in the form.  When that happens it throws an error.  SCR 147132.  Here was the post on Answers.

Also here is all the code in the JS section.  Just changed the servername for the purpose of this post.

$(document).ready(function () { 
  document.title = 'VATS-Edit Assets';
  $('.roinput input').prop('readonly',true);
  $('.email input').attr({'type' : 'email'});
  $('.hideme input').hide();
  $('head').append('<link rel="stylesheet" href="http://servername/forms/styles/mdva.css" type="text/css" />');
  $('head').append('<script src="/Forms/scripts/mdva.js" type="text\/javascript"><\/script>');
  loading("#Field10");
  
  $('.cf-table-block').on('change', 'input', sumtotal);
});


function sumtotal() {
  var sum = 0;
  $('td.asset').each(function () {
    var s = 0;
    $(this).find('input').each(function () { s += parseNumber($(this).val()); })
    sum += s;
  });
  $('.total input').val(sum-1);
}

function parseNumber(n) {
  var f = parseFloat(n);   //Convert to float number.
  return isNaN(f) ? 0 : f; //treat invalid input as 0;
}

 

0 0
replied on September 4, 2016

Still I'm not able to reproduce the issue. 

In my testing, the total field is empty on form load, and keeps empty when adding a new row. Also the total field value can be updated correctly when filling the Verified Balance column.

Can you try creating a new process with only a table and a total field, and see if the script work as expected?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.