Copy link to clipboard
Copied
Hi there,
I need to set up a form field name array to check if the field names "8 base 2" to "8 base 8" are visible. If they are visible then I will need to show then next one to show along with the Name, Sig and Date boxes. Also when it shows "8 base 5" Page 2 needs to be spawned. I have asked this previously last week but when it came to spawning a new page it stopped working.
Copy link to clipboard
Copied
This line is invalid:
var f = this.getField(visibleFields);
It needs to be:
var f = this.getField(visibleFields[i]);
Also, do not use the spawnPageFromTemplate method. It's been replaced by the spawn method of the Template object itself.
Copy link to clipboard
Copied
Probably because all three fields are visible... Either check only one of them, or break the loop after spawning a new page, so the rest don't get checked.
Copy link to clipboard
Copied
Try to correct this first (the equal sign must be doubled):
if (f) f.display == display.visible {
Copy link to clipboard
Copied
Correct. It needs to be:
if (f.display==display.visible) {
Copy link to clipboard
Copied
The if is not correct.
Copy link to clipboard
Copied
This line is invalid:
var f = this.getField(visibleFields);
It needs to be:
var f = this.getField(visibleFields[i]);
Also, do not use the spawnPageFromTemplate method. It's been replaced by the spawn method of the Template object itself.
Copy link to clipboard
Copied
Thanks for your help but getting error| TypeError: this.getField(...) is null 7:AcroForm:Button 5:Annot1:MouseUp:Action1.
Can't see the naming convention wrong in any way.
Copy link to clipboard
Copied
Print out the field name in each iteration so you can see which one is causing it.
You have to make sure the field names in your array match the actual ones PERFECTLY. A single character off (including spaces, upper/lower-case letters, etc.) will cause it to fail.
Copy link to clipboard
Copied
I have now changed the code to the below but the spawn page is repeating 3 times?
Anything I am doing wrong with it.
var visibleFields = ["8 base 2", "8 base 3", "8 base 4"];
for (var i in visibleFields) {
var f = this.getField(visibleFields[i]);
if (f.display==display.visible) {
this.getTemplate("Page 2").spawn(1, false, false); this.getField("Date5").display = display.visible; this.getField("Sig5").display = display.visible; this.getField("Name5").display = display.visible; this.getField("8 base 5").display = display.visible;
}
}
Copy link to clipboard
Copied
Probably because all three fields are visible... Either check only one of them, or break the loop after spawning a new page, so the rest don't get checked.
Copy link to clipboard
Copied
Thanks Try67,
You're a genius.
Copy link to clipboard
Copied
Another way to implement this functionality is to use group naming for the fields. This would make the process more easily expandable, robust, and simplify it.
For example, use these field names: "8base.2", "8base.3", "8base.4"
Then the code can be written like this:
this.getField("8base").getArray().forEach(function(oFld){
if (oFld.display == display.visible) {
template.spawn(...);
... other code ...
}
});
And there is another issue that the other posters didn't mention. Don't use the spawnPageFromTemplate function. Use the "template.spawn()" function.
Copy link to clipboard
Copied
I did mention it, actually... 😊
Copy link to clipboard
Copied
I see that now. It's aways in the details 🙂
Copy link to clipboard
Copied
Just noticed another error in your code, namely here:
nPage: v+2,
There's no variable called "v" defined anywhere in it.