Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Calculations in Dynamic Table Problem (& more).. HELP!

Avatar

Former Community Member
Hello - If someone could help me it would be greatly appreciated!

I have uploaded the form to 'yousendit'



It can be downloaded here (80 kb) to make my explanations clearer!



http://www.yousendit.com/transfer.php?action=download&ufid=3DCF47194D020CB0



I have a dynamic table with a few calculations..



unit cost * quantity = total price



plus a field at the bottom of the table which is a sum of the 'total price'



I'm having a few problems though..



1. After adding a 2nd (or next) row, & adding values for unit cost & quantity for the new row, it does not calculate the grand total immediately. I have to make a change to the 1st row again & then it adds the totals of both rows - Could someone please tell me how to alter the script in order to recalculate everytime i change a value in the table?



2. When i delete a row, it does not recalculate... but keeps the totals of all rows which were there previously!.. How can i recalculate whenever a row is deleted?



3. If i enter a value in a field, i have to click twice inside another field to place the cursor there / to enter a value in another field.



How can i avoid this?



Thank you very much in advance!
8 Replies

Avatar

Former Community Member
Hi Chris.



In regards to 1), try:



var jpt = xfa.form.form1.subform5.resolveNodes("sub3[*]");

var sum = 0.0;

for (i = 0; i < jpt.length; i++) sum += jpt.item(i).resolveNode("MP").rawValue;

this.rawValue = sum;



In this case, the name of my form is form1, the parent subform is subform5, the table is contained in sub3 and the field I want totalled is MP. This script should be placed in the calculate event of the field you want the total to show up in, after you modify it to reflect your form/subform/field names.



In regards to 2), try:



xfa.form.recalculate(1);



Place this in the click event of your Delete Row button.



In regards to 3), I'm still working on it ;).



Dave

Avatar

Former Community Member
Thank you ! What i did in the end was add the 'recalculate' script to both fields so that it calculates everytime a value is changed - Thank you very much for your time :) #3 is a strange one though :|

Avatar

Former Community Member
Sorry for 'taking advantage' of your knowledge & time.. but one more problem of the few that I currently have is the form is very slow. The calculations I guess will be slowing it down a little bit, but not this much..The 'almost complete' form has 2 pages. The dynamic table is on the 2nd page & when I add/delete a row, or add values to the fields, it takes some time to execute..



I deleted the 1st page just to see if it would make any difference & unfortunately, it did.. Rows can be added instantly, calculations are quickly performed. I uploaded the 2 page form (110 kb) -



If someone has the time, could they please take a quick look at it & tell me if it is normal or not for taking so long to add a row or calculate - I don't know if it's behaving normally considering the number of fields currently in the form, or if rearranging the hierarchy would help it at all (?)..



http://download.yousendit.com/A3FB4A8922147D85



Once again, thank you

Avatar

Former Community Member
Hello, I have followed advice from two articles on Improving the performance of Livecycle Designer Forms but cannot seem to make the form rerender any faster.. I have changed fonts, removed calculations just as a test, unwrapped unnecessary subforms etc..



Is it normal for a 2 page form to take so long to calculate / add instances to a subform? Thank you

Avatar

Former Community Member
Hi Chris, I did take a look at your form and I didn't think it performed all that badly. It will take a second or two for the form to recalculate when you have the xfa.form.recalculate(1); script running, but other than that I thought it did pretty well. I don't think the length of the form has much to do with it, I think it's that your adding up totals in a subform.



Having said that, are you having problems with other parts of the form, or just the table doing the calculations?



Dave

Avatar

Former Community Member
Thanks very much! well.. when you add a new item, the scrollbar moves up, down & it take some time to add a new item....same thing with exiting a form field.. It seems to take quite long for a relatively 'small' form.. I will try to add validate scripts rather than recalculate... just to see if it will make anything quicker!



Thanks again!!

Avatar

Former Community Member
HI Chris, if I'm not mistaken taking out the recalculate will keep your subform from keeping a running total on your form. If you do decide to try some alternative to speed the form up, I strongly suggest saving a copy of the form as is and saving a second copy under a different name to make your changes.



Dave

Avatar

Former Community Member
Thanks for the advice.. Yes, with Designer, I always end up with about 12 versions of each form :) - In Acroforms, you were able to add javascript to the VALIDATE function.. Required more scripting as it was added to each field (which would be used in calculations) ...but it would only affect the fields involved in a particular calculation when a change was made..



Adding the script to 'CALCULATE' would execute each & every calculation on the form everytime any value change was made to a field! which would make the form extremely slow..



I was hoping there was something similar in Designer, but if im not mistaken, it seems you can't write such scripts in the validate event... :|