Skip to main content
khyleew20598231
Participant
June 28, 2023
Answered

JAVA SCRIPT - Creating a new page with same fillable fields and add image options but cleared out!

  • June 28, 2023
  • 1 reply
  • 680 views

Need help with creating javascript that allows me to "duplicate" a page that contains fillable fields, drop downs and "add image" feautres but basically "resets" the fields to being empty.

 

1. I have two action buttons. CLEAR PAGE which contains: 

var fieldsNotToReset = ["Text1", "Text10", "Text24", "Radio1", "Dropdown5"]; // Replace with actual field names
var fieldsToReset = [];
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f==null) continue;
if (f.type=="button") continue;
if (fieldsNotToReset.indexOf(fname)!=-1) continue;
fieldsToReset.push(fname);
}
this.resetForm(fieldsToReset);var buttonIcon = this.getField("Click here").buttonGetIcon();this.getField("Click here").buttonGetIcon();
this.getField(event.target.name.replace("blank", "Image1")).buttonSetIcon(buttonIcon);

 

and the 2. ADD PAGE: 

var expTplt = getTemplate("88TH RD MAIN PAGE");

expTplt.spawn(numPages,true,false);

 

IDEALLY, I am able to "ADD PAGE" and create a new page with empty fields and clearing the image however I realize you can not duplicate a page with image fields and remove the images. My main goal is to just duplicate pages and fill in blank fields as you go. Right now the JAVA SCRIPT for add page duplicates all data and the CLEAR PAGE on the duplicated page clears EVERTHING from the entire PDF. 

 

Please help!

 

 

This topic has been closed for replies.
Correct answer try67

All you have to do is add a condition to the code that resets the fields to only add those fields that are on the last page of the file to the list of fields to reset. And of course, run this command after you spawn the new page.

The image fields are trickier, though, as they can't be reset directly. The way around that is to create a (hidden) image field without an icon and then copy its icon to them. That will remove any image they currently have selected.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 28, 2023

All you have to do is add a condition to the code that resets the fields to only add those fields that are on the last page of the file to the list of fields to reset. And of course, run this command after you spawn the new page.

The image fields are trickier, though, as they can't be reset directly. The way around that is to create a (hidden) image field without an icon and then copy its icon to them. That will remove any image they currently have selected.

khyleew20598231
Participant
June 28, 2023

Thanks for the feedback! So basically run a condition on the javascript for the "clear page" not adjust the add page feature? Any idea on how to do that....I am completely lost on how

try67
Community Expert
Community Expert
June 30, 2023

You need to check the field's page property. However, this can get tricky as that property will return an array of numbers in case there are multiple instances of that field (for example, if it's a group of check-boxes or radio-buttons). In that case you will need to check if the page number is without that array.