Copy link to clipboard
Copied
Hi experts, trying to reset form fields but only on the spawned page using a 'button'. Right now it resets both spawned and original page. Thanks for any assistance!
Copy link to clipboard
Copied
In order to reset only the fields on a spawned page you need to use a script that dynamically works out the name of the fields to reset.
For example. If the button is named "Reset". Then on the spawned page it will be named "P#.TemplateName.Reset".
If you were to hard code the reset field names, then you would need to run this script.
this.resetForm( "P#.TemplateName");
To generalize the code so that it works on any template page, the script needs to extract the template prefix from the name of the reset button. Like this:
var strPrefix = event.targetName.split(".").splice(0,2).join(".");
this.resetForm(strPrefix);
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Have you renamed the form fields on the spawned page?
Copy link to clipboard
Copied
Hi Bernd, yes. It is a hidden template, I had renamed all the hidden template fields to start with "P0.templatename.fieldname". I now see on the spawned page, all fields are renamed to "P2.templatename.P0.templatename.fieldname"
Copy link to clipboard
Copied
Why does you use this form field names on the template page?
Copy link to clipboard
Copied
I read on another forum page that you should rename hidden template fields to the "P0..." format. Was this not correct?
Copy link to clipboard
Copied
Yes
Copy link to clipboard
Copied
In order to reset only the fields on a spawned page you need to use a script that dynamically works out the name of the fields to reset.
For example. If the button is named "Reset". Then on the spawned page it will be named "P#.TemplateName.Reset".
If you were to hard code the reset field names, then you would need to run this script.
this.resetForm( "P#.TemplateName");
To generalize the code so that it works on any template page, the script needs to extract the template prefix from the name of the reset button. Like this:
var strPrefix = event.targetName.split(".").splice(0,2).join(".");
this.resetForm(strPrefix);
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thom, thank you so much! Works perfectly 🙂
Copy link to clipboard
Copied
You're welcome! A best Answer would be helpful.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
My apologies, I clicked the wrong one! Fixed now. Thanks again 🙂
Copy link to clipboard
Copied
Thom this worked beautifully for the single page form that I needed to spawn from a template and clear the fields. Can you share how this would work with a multipage form? I use this code to spawn the two page form:
var expTplt = getTemplate("CIP1") ; expTplt.spawn(pageNum+1,true,false) ;
var expTplt = getTemplate("CIP2") ; expTplt.spawn(pageNum+1,true,false) ;

