• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript to make all fields visible

New Here ,
Jan 30, 2023 Jan 30, 2023

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;
}

TOPICS
Acrobat SDK and JavaScript , Windows

Views

261

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2023 Jan 30, 2023

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;
	}
	
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2023 Jan 30, 2023

Copy link to clipboard

Copied

grouping work as well?

coz over 100 fields 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2023 Jan 30, 2023

Copy link to clipboard

Copied

What do you mean by "grouping"?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2023 Jan 30, 2023

Copy link to clipboard

Copied

LATEST

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

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines