Skip to main content
Participant
April 10, 2020
Question

JavaScript Add Page, Delete Page, and Clear Page Buttons

  • April 10, 2020
  • 1 reply
  • 861 views

I have a fillable form and have created the three buttons listed in the subject. I am having issues with the Add Page button and Clear Page button working the way I need too.

 

When I click "Add Page"  it creates the new page but it copies all the data from the first page.

JavaScript

car a = this.getTemplate ("Name"); a.spawn();

 

When I click " Clear Page" it clears the entire document not just the page I'm on when I click the button.

JavaScript

if( app.alert({

cMsg: "Are you sure you want to Clear",

cTitle: "Reset Warning",

nIcon: 2,

nType: 2

}) == 4) {

this.resetForm();

}

 

I am basically attempting to add a new page to the document that is the exact same as the first but is blank. I need the buttons to work independently from page to page only affecting the page the button is on. For example if a user needs to start over on page 5 without having to redo pages 1-4 they can click the button and start over. I have no clue what I'm doing any help would be appreciated. 

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
April 10, 2020

Please refer to the reference for the template.spawn() function:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FTemplate_methods.htm%23TOC_spawnbc-1&rhtocid=_6_1_8_74_1_0

 

Note the "bRename" input parameter. 

Fields that have the same name have the save value. Id est, if you want unique fields with unique values, they have to be renamed. 

 

Again, for the reset button see the reference for that function. The input argument is an array of  fields to be reset.

Fortunately it works with group naming, so you can use the renamed field prefix to reset all the fields on that page. 

For example:

 

this.resetForm(event.targetName.split(".").shift());

 

This line will reset all renamed fields on a spawned templage page.  It only works for this specific condition. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often