Skip to main content
Known Participant
February 8, 2023
Answered

Templates rename fields when they are spawned.

  • February 8, 2023
  • 2 replies
  • 1925 views

I have a form with a checkbox to spawn different templates when the appropriate box is checked. When I check the button, it renames the fields to the name of the template and the name I've given to the field. Is there way to stop the template name from becoming part of the field name?

 

This topic has been closed for replies.
Correct answer Thom Parker

I tried another and this doesn't do it.

 

if(event.target.value == "Yes"){
this.getTemplate("Authorities4-6").spawn(event.target.page+1, true, false);
this.pageNum = event.target.page+1;
bRename:false;}
else
this.deletePages(event.target.page+1);


Good try, you are not far off, but there are a couple of errors.

First, the "bRename:false;" line is meaningless. In fact it's a syntax error that will prevent the code from even starting to execute. Delete it.  You should have seen this in the console window. 

 

But, the insidious error is this code event.target.page+1 

If there is another copy of the check box on the form, i.e., a checkbox with the same field name, then the "page" property will be an array of page numbers, one for each instance of the field. If you know there is only one copy of the field then you're ok, but this something to be aware of. The page property is not always a number. 

 

Last but not least, because it was the point of your post in the first place, the "bRename" argument of the spawn function must be set to false, it's true in your code right now.

Change the spawn line to this:

this.getTemplate("Authorities4-6").spawn(event.target.page+1, false, false);

 

Otherwise it looks like the code is good to go.

 

 

 

 

 

 

2 replies

Thom Parker
Community Expert
Community Expert
February 8, 2023

See the entry for the "template.spawn" method in the Acrobat JavaScript Reference.

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#spawn

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Nesa Nurani
Community Expert
Community Expert
February 8, 2023

In the script to spawn template, set 'bRename' to 'false'.

Known Participant
February 8, 2023

I have tried a couple of different ways to enter the command into the coding, but can't figure this out.  Can you please help me? I'm so new to this.

if(event.target.value == "Yes"){
this.getTemplate("Authorities4-6").spawn(event.target.page+1, true, false).(bRename,false);
this.pageNum = event.target.page+1;
bRename,false;}
else
this.deletePages(event.target.page+1);

Known Participant
February 8, 2023

I tried another and this doesn't do it.

 

if(event.target.value == "Yes"){
this.getTemplate("Authorities4-6").spawn(event.target.page+1, true, false);
this.pageNum = event.target.page+1;
bRename:false;}
else
this.deletePages(event.target.page+1);