Hide/show layer and fields (interactive pdf)

New Here ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

Hope someone is able to help with my question: How can I make layer visible (a pop up message) with a button click and hide all the other fields on a page at the same time, and revert back (hide layer and make all the fields visible) on another click of the same button. Thanks!

TOPICS
Acrobat SDK and JavaScript

Views

908

Likes

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
Adobe Community Professional ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

You can do this with the show/hide field function.

Your alert/message is one button, easiest is just to have it cover all other fields in stack order you can add as many show/hide functions as you like to show/hide additional form items.

Clicking somewhere on the alert button will hide itself (and if necessary show other buttons/fields).

This can be done in Acrobat or in InDesign. Giving good names is the key to keep you from going crazy.

Likes

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
Adobe Community Professional ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

Here's a good tutorial on working with layers (OCGs) using JavaScript: https://acrobatusers.com/tutorials/creating-and-using-layers-ocgs-with-acrobat-javascript

To control the visibility or form fields, use the "display" field property, for example:

// Show this field

getField("text1").display = display.visible;

If you use hierarchical field naming for the group of fields that you want to control (e.g., group1.text1, group1.text2, group1.checkbox4, etc), you can show/hide all of the fields in the group with a single statement:

// Hide all of the group1 fields

getField("group1").display = display.hidden;

Likes

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 ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

Thank you for your insight, George. But I feel like I need a conditional statement for desired functionality to work. I was able to find this js code:

var layerName = "Chart1";

var layers = this.getOCGs();

if (layers!=null && layers.length!=0) {

for (var i in layers) {

if (layers.name==layerName) {

layers.state = !layers.state;

break;

}

}

}

This works - shows my hidden layer but I need to hide the rest of the fields on this page so that they don't show on top of my pop-up layer. Next I need to hide my pop-up layer on another click and show my fields back again.

Likes

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
Most Valuable Participant ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

A layer is not defined on a specific page. You will need to hard-code the page number into the code, if you want to do it.

Likes

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
Adobe Community Professional ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

LATEST

You can show or hide a field with a single statement or a groups of fields with a single statement, like I showed. If you don't want to change your field names, you'll have to show/hide each field individually.

Likes

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