Copy link to clipboard
Copied
I am completely new with javscrtipt.
I got over 100 fileds in form and wanna show them all with one click. Is there any way of doing with simple scripting other than calling the field one by one ?
var r1 = this.getField("aa");
var r2 = this.getField("bb");
var r3 = this.getField("cc");
var r4 = this.getField("dd");
var flagBtn = this.getField("Flag");
var showAll = flagBtn.buttonGetCaption();
if(showAll == '0')
{
flagBtn.buttonSetCaption('1');
r1.display = display.visible;
r2.display = display.visible;
r3.display = display.visible;
r4.display = display.visible;
}
else
{
flagBtn.buttonSetCaption('0');
r1.display = display.hidden;
r2.display = display.hidden;
r3.display = display.hidden;
r4.display = display.hidden;
}
Copy link to clipboard
Copied
You can put the names in an array and then use a loop to access all of them, like this:
var fields = ["aa", "bb", "cc", "dd"];
var flagBtn = this.getField("Flag");
var showAll = flagBtn.buttonGetCaption();
if (showAll == '0') {
flagBtn.buttonSetCaption('1');
for (var i=0; i<fields.length; i++) {
var f = this.getField(fields[i]);
f.display = display.visible;
}
} else {
flagBtn.buttonSetCaption('0');
for (var i=0; i<fields.length; i++) {
var f = this.getField(fields[i]);
f.display = display.hidden;
}
}
Copy link to clipboard
Copied
grouping work as well?
coz over 100 fields
Copy link to clipboard
Copied
What do you mean by "grouping"?
Copy link to clipboard
Copied
If by grouping you mean using the "dot" field naming notation, then yes. It's the best way to provide easy access to a group of fields for scripting purposes.
You can find out more here (watch the video on field nameing):
https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm