I made my first form and everything is working good. That was my first time creating a form and my first try with JS. I know thatmy calculations are porbably not optimal, but i'd like to figure out something without starting all over or make dramatic changes to my form.
I'd like to know if there is a way for my calculations to be faster.
There is a little delay when choosing an item in many fields but specifically in those fields :
Type de collage
I can see that the calculations are runing. It could be anoying for the customer to wait everytime he choose an item.
If someone has a clue for me it would be appreciated.
I am working on Adobe Acrobat Pro DC.
My form is in french.
Here is the link to my form :
Calculations are problematic because they are triggered every time any field value is changed, which means they are usually run many more times than necessary. In fact, it's quite easy to create huge cascades of unnecessary calculations.
The solution is to reduce the number of calculation scripts. There are several methods for fixing this issue.
1) Move anything that doesn't need to be a calculation into a different type of script. The obvious targets are any calculation that only depends on one input. This can probably be moved to a validation script on the source field.
2) Test for the source of a calculation before proceeding. If the source is not one of the inputs to the calc, then don't run the code.
3) Make sure your calculations are not spawning other calculations. This happens when a calculation script directly changes a field other than itself. If you have calculations that do this, then it should probably be done a different way.
BTW: sharing you document as a review is problematic. If you want us to examine it, it should be shared as a plain file.
Thanks for the advices.
I just didn't know how to share it plain.
You should be able to add it to this thread by editing your first post. The edit will include a paper clip symbol for attaching a file.
I see no options to edit my first post....
If there isn't a "... More" link under the post, then you could share the document through Google Docs or DropBox.
You should also fix the script errors in the form.
I don't know how to do that though.
It's my first time using JS, so I probably don't know how to use it correctly yet.
Look at the JS console for the error messages.
You'll find a video on how to use the Console Window here:
You should also read this page:
The main error is a bad field name, used in "this.getField" in one of the calculation scripts.
A major problem with form is that most of your calculations should not be calculations. From what I can see, every calculation script used on on a dropdown, should be a validation script. Fixing this would probably fix the slowness.
Thanks a lot. Can you tell me which field name is in error ?
I'll have a look on the links you just send.
Really appreciate your help.
That is an exersise left to the user 😉
I would suggest moving all the calculation scripts on the dropdowns to validation scripts. Then it will become apparent (in the console) when you do a selection.
Field names must be verbatim in every place they are used.
So, I was able to switch a part of my calculations into validations scripts but there is one remaining that I don't know how to figure out.
This is the calculation of the "Découpe" field.
Basically, what I wanted from that calculation is to check the box " Dessin" when one of those field is not empty or when a specific radio button is at yes.
If field Découpe or Assemblage-Dessus or Assemblage pattes is not empty
OR if Porteafaux is checked at YES
OR if field Moulurage value is Personnalisé
Then I want my Dessin checkbox to be checked
I don't know how to do it differently by using validation script in each field. Every try I made didn't work out well. My value was cleared by the choice made in my second drop down. Even if Decoupe field was not empty, when I cleared field Assemblage-Dessus, it just cleared Dessin box, but my field Decoupe was still filled.
More, I don't know how to add my radio button into that condition.
Wondering if you could help me again,
Good for you!! It's well worth the effort to try different ways to script a behavior, even if it doesn't work out. However, since setting the "Dessin" depends on several inputs, it is appropiate to use a Calculation Script, just not on the dropdown. Instead, put a new text field next to the "Dessin" checkbox, and use the calculation script on this text box. Make this text field hidden. This separates the code for the calculation from the source fields.
Now you need to learn a bit about how to write calculations.
These short article can help:
In this case the calculation isn't with numbers, but with boolean values.
Here's the calculation script for the hidden text field next to the "Dessin" checkbox
var bDessinValue = (this.getField("Decoupe").valueAsString != "0") || (this.getField("Assemblagedessus").valueAsString != "0") || (this.getField("Assemblagepattes").value != 0) || (this.getField("Moulurage").value =="Personnalisé") || (this.getField("Porteafaux") == "Oui"); this.getField("Dessin").value = bDessinValue?"Yes":"Off";
Thanks a lot again.
I read the articles but since I am not a member of this website, I can't read all the information.
But I think I'll figure something out with the code you provided.
It is working great except for the Porteafaux radio button. This part of the code don't seam to work.
Even if I checked Oui, the Dessin box is not checking.
If you look carefully you'll see there is an error in the code. The line of code that tests the Porteafaux field does not acquire the "value" property. Here's the correction.
|| (this.getField("Porteafaux").value == "Oui");
Thanks a lot. It works perfectly.
I'm grateful you helped me with my project.
In the newer versions of Acrobat the error message doesn't include the name of the field you were trying to access that caused the error, just "...", which makes it incredible difficult to locate the issue, since the name of the field that triggered it is also not included. Luckily, I have access to an older version so I can help you locate the issues. Here's the full text of the error messages I'm getting from the file you shared:
TypeError: this.getField("P" + (this.numPages - 1) + ".JONH" + ".Typedecollage6") is null 1:Field:Calculate TypeError: this.getField("P" + (this.numPages - 1) + ".JONH" + ".Typedecollage5") is null 1:Field:Calculate TypeError: this.getField("P" + (this.numPages - 1) + ".JONH" + ".Porteafaux4") is null 1:Field:Calculate TypeError: this.getField("P" + (this.numPages - 1) + ".JONH" + ".Porteafaux5") is null 1:Field:Calculate TypeError: this.getField("P" + (this.numPages - 1) + ".JONH" + ".Porteafaux6") is null 1:Field:Calculate TypeError: this.getField("P" + (this.numPages - 1) + ".JONH" + ".Typedecollage4") is null 1:Field:Calculate
(these fields were supposed to be on a page spawned from the "JONH" template, but it hasn't been spawed yet...)
Thanks a lot ! I'll try to solve this error.