Expand my Community achievements bar.

Dynamic Form Calculation

Avatar

Former Community Member
I have been playing with the "Interactive Expense Report" in the samples area. I have created my own version that performs the same function....dynamically adding lines to record expense information. What I'm having trouble with is the sum (total) calculation of all these records as they are added by the user.



I pretty much repeated the code from the sample document, changed the appropriate object references and at the moment it calculates the total for 1st line....but as lines are added it does not keep adding it up. Here is the code if it helps...thoughts?



var jpt = xfa.form.pettyform.page1.resolveNodes("pettysubform[*]");



var sum = 0.0;

for (i = 0; i < jpt.length; i++)

sum += jpt.item(i).resolveNode("numAmount").rawValue;



this.rawValue = sum;
3 Replies

Avatar

Former Community Member
Instead of a thought, here's some questions? I'm assuming this script is on the field for the sum in the calculate event? If you put an xfa.host.messageBox() on the top, is the script getting triggered? If you hit Ctrl-J, any errors showing up in the JavaScript console?



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Your are correct the script is on the calculate event of a numeric field. No errors with Debugger. I put a message box in several areas of the code, it triggers properly, and the first line is calculated. Nothing afterwards.



I added a button that recalculates the form xfa.form.recalculate(1); when I click this button the form is calculated correctly, multiple dynamic lines and all.



Just not sure why the original code is not doing it automatically. Can I post anything else that would help? Not being a JS expert all I can say is logically the script works, short of sum action, just not recognizing the dynamically added lines as additional fields to calculate.

Avatar

Former Community Member
The fact that calling xfa.form.recalculate(1) gives the expected result tells me that the script is OK and it sounds like the sample involves adding lines/rows dynamically which should then participate in the form's overall calculations, which leads me to think that this problem is similar to the one discussed on the following thread:
Dynamically added subforms don't trigger recalculations.



Stefan

Adobe Systems