Working with Visibility Layers and saving view state

Explorer ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

I reached out to the community about showing/hiding multiple visibility layers based on a drop down and/or check box selections in June (https://community.adobe.com/t5/acrobat/working-with-visibility-layers/td-p/12108213) . Thanks to Thom Parker for providing me with the solution I was looking for.

 

The new problem: when a form is saved with selected layers visible and then reopened, the selected layers are no longer visible. The fillable fields (including the trigger check boxes and/or drop downs) remain filled, but the associated layers are now hidden. 

 

I've found similar issues discussed and have tried various document level javascript solutions, but none seem to work for me. Either they make all layers hidden or all layers visible upon reopening (not just the "triggered" layer(s) and default/base layer).

 

Any help would be greatly appreciated.

TOPICS
How to , JavaScript , PDF forms

Views

325

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

correct answers 1 Correct answer

Adobe Community Professional , Jul 02, 2021 Jul 02, 2021
Add this line after the line that starts with "layers[i].state = ...": layers[i].initState = layers[i].state;

Likes

Translate

Translate
Adobe Community Professional ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

You need to save the state of the layers when the file is saved to a (hidden) field, or even the file's metadata, and then use a script to read that value when the file is opened and set the visibility of the layers based on it. You can also change the layers' initState property, but only if the file is going to be used exclusively in Acrobat, as that won't work in Reader.

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 ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

I need this form to be user friendly. Different users are going to be making different choices (causing different layers to be visible/hidden) when they save and send their filled form, I need the corresponding layers to remain visible/hidden. Does this make sense? For the record, all users will be using Acrobat (not reader)

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 ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

What I described is entirely transparent to the user. They will not notice it at all.

However, if they are all using Acrobat then it's very easy. In your code that changes the state property of the layer also change the initState property to the same value.

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 ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

great. How would I do that?

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 ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

Exactly like I wrote.

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
Explorer ,
Jul 02, 2021 Jul 02, 2021

Copy link to clipboard

Copied

You wrote:

"In your code that changes the state property of the layer also change the initState property to the same value." Unfortunately, I'm not sure how to do this.

 

Currently, my form has 16 "variable" layers and 1 default/base layer. For the layers that are triggered by a check box, this is the mouse up action script that is being used:

var layers = this.getOCGs();
for (var i = 0; i < this.layers.length; i++) {
if((new RegExp("^" + event.target.name)).test(layers[i].name))
layers[i].state = (layers[i].name == (event.target.name + "." + event.target.value));
}

 

What should be added to this code to make the visibility of the selected layer remain on when a trigger check box is selected and the form is reopened after saving? (The Layer Properties for all the variable layers are set to: Default State=On and Intial State Visibility=Visible When On). Thanks for all your help.

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 ,
Jul 02, 2021 Jul 02, 2021

Copy link to clipboard

Copied

Add this line after the line that starts with "layers[i].state = ...":

layers[i].initState = layers[i].state;

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
Explorer ,
Jul 02, 2021 Jul 02, 2021

Copy link to clipboard

Copied

That works perfectly. Thank you so much!

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 ,
Sep 07, 2021 Sep 07, 2021

Copy link to clipboard

Copied

hi ! I've been dealing with the same problem  and wondering if you can help me. I'm using a custom calculation script based on one someone showed me ( it's my first time working with a FORM) It's multiple layers activated by a dropdown menu, where do I add the line ?

 

 var layer = this.getOCGs();

for(var i=0; i<layer.length; i++) {

if(event.target.value=="NOIR / BLACK")

   { if(layer[i].name=="BASE_black") {layer[i].state=true}

   { if(layer[i].name=="BASE_white") {layer[i].state=false}

 

thank you !

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 ,
Sep 07, 2021 Sep 07, 2021

Copy link to clipboard

Copied

Change this:

layer[i].state=true

To:

layer[i].state=true; layer[i].initState=true;

 

Note that the second part won't work in Reader, though, only Acrobat.

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 ,
May 03, 2022 May 03, 2022

Copy link to clipboard

Copied

LATEST

Hi Guys, I'm having the same problem with my layers not showing as described at the top of this thread. I have used the show/hide functions and based on radio button selections and have not used a Java script in the document or ever before.

 

So I'm a  it lost as to how this to go about implementing a Java script fix to show the correct layer once the document is saved and reopened. 

 

Could you provide a step by step guide please? 🙏 

 

 

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