Copy link to clipboard
Copied
(semi)newbie to javascript - go (somewhat) easy on me :O)
short version... working on a form where I need to either show a bunch of fields or hide them base on radio button choice.
Right now I have the fields visible (or hidden) based on the button's Action/Show/Hide Field. It works but there are +/-75 fields and it's cumbersome, at best.
Logically, I would like to group those +/-75 feilds but have no idea if this is available!?
Any help would be appreciated.
Copy link to clipboard
Copied
Name the fields in the group with a hierarchical numbering scheme creating the first field, then right-click>Create multiple copies with 1 across and the rest down. You will end up with fields named, for example, Text1.0 through Text1.74. You can then create a calculation that loops through the fields and sets the visibility (display property). Alternatively, you can put a custom calculation in the first field before using right-click > Create multiple copies that will show or hide depending on the value of the radio button choice:
if(this.getField("Radio 1").value == "A")
{event.target.display=display.hidden}
else
{event.target.display=display.visible}
If your fields don't have a numbering scheme and you don't want to individually enter a calculation script into every single field, this trick is for you:
https://pdfautomationstation.substack.com/p/secret-trick-for-changing-properties
Copy link to clipboard
Copied
Great info (for the next one :O/)!
Any easier way (short of renaming) if I have the 75+ fields (consisting of radio buttons, check boxes and text boxes) already named?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
THANKS!! AND, while I'm being greedy here...
Is there a way to generate and export a list of feild names either by page or as a whole?
Copy link to clipboard
Copied
Here's a specific explanation on how to show/hide fields:
https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm
And yes there is a way to generate and export a list of fields and their properties, but it's not a feature of Acrobat. You need a script for it.
See the first tool on this list of free tools: "Find Required Fields"
https://www.pdfscripting.com/public/Free_Acrobat_Automation_Tools.cfm
Here's an example of some code you could run from the console window.
var strReport = "";
for(var i=0;i<this.numFields;i++)
{
strReport += this.getNthFieldName(i) + "\n";
}
this.createDataObject("FieldNameList.txt", strReport);
This short script collects all field names into a variable named strReport, and then uses it to create a text file attachment to the current PDF.
Copy link to clipboard
Copied
console is generating an error msg:
var strReport = " ";
for(var i=0;i<this.numFields;i++)
{
strReport += this.getNthFieldName(i) + "\n";
}
this.createDataObject("FieldNameList.txt", strReport);
ReferenceError: strReport is not defined
1:Console:Exec
undefined
Copy link to clipboard
Copied
Are you copying, pasting, and selecting the entire code before running it? That error would suggest you ran the last line only.
https://pdfautomationstation.substack.com/p/the-javascript-console
Copy link to clipboard
Copied
sorry for the delay - had to get the form done (as best as I could) and submitted. Would still really like to get this figured out as I knw there will be revisions.
so the short answer is yes, I did highlight everything and hit enter from my keypad (like your video instructs) but am still getting a null error
interestingly, if I add PDF Automation's line (this.exportDataObject({cName:"FieldNameList.txt", nLaunch:2});) it works and generates a text file - attached.
Possible syntax error in the (this.createDataObject("FieldNameList.txt", strReport);) function?
Copy link to clipboard
Copied
The error is that the variable strReport is not defined. It gets defined in the first line of the script as an empty string. It then gets field names added to the string in the loop. It is then used to create the data object in the last line of the script. There shouldn't be an undefined error for the strReport variable. When you run this.exportDataObject({cName:"FieldNameList.txt", nLaunch:2}); and it opens the text file, that means the script was successful in creating the data object.
You can also delete all attachments and run the script with the attachments panel open. You should see the file appear.
Copy link to clipboard
Copied
Use @Thom Parker 's script. If you add this line at the end it will open the attachment when finished:
this.exportDataObject({cName:"FieldNameList.txt", nLaunch:2});
Find more inspiration, events, and resources on the new Adobe Community
Explore Now