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

Multiple Yes/No Radio Buttons to show/hide both fields and text label overlay(s)

Participant ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

After an inordinate amount of research here, I thought everything was working well until... (que ominous music)... I actually used it. Not terribly surprising to y'all but hey, I'm trying. 😉

Anyway, I have a number of different "Yes/No" radio buttons where, ideally, they will display/hide additional fields AND their respective text label overlays.  While it "appeared" to work intially, I did not notice that the specific "Yes/No" radio buttons were turning all other overlays on or off irrespective of the varying overlay names.  After attempting to research and tinker, I am now unable to get any of the overlays to turn on/off via JS only the fields leading me one again to the forum Subject Matter Experts (SMEs) offering advice and their expertise.  So, once again, here I am.  

In my attempt to employ the KISS principle and keep the JS as clean and neat as many of the examples provided here, I have clearly missed something -- or a whole lot of everything.  My sincerest thanks in advance for your assistance.

Here is what populates the Actions, Run a JavaScript in one of the "Yes" boxes:
this.getField("Photos").display = display.visible;
this.getField("Diagrams").display = display.visible;
this.getOCGs("Photos&Diagrams").state = true;

Here is what populates the Actions, Run a JavaScript in it's paired "No" box:
this.getField("Photos").display = display.hidden;
this.getField("Diagrams").display = display.hidden;
this.getDataObject("Photos&Diagrams").state = false;

Here is what populates the Actions, Run a JavaScript in another of the "Yes" boxes:

this.getField("LogEntry_Deck").display = display.visible;
this.getField("LogEntry_Engine").display = display.visible;
this.getField("LogEntry_Official").display = display.visible;
this.getField("Incident_MTF").display = display.visible;
this.getDataObject("LogEntries").state = true;

 

Here is what populates the Actions, Run a JavaScript in it's paired "No" box:

this.getField("LogEntry_Deck").display = display.hidden;
this.getField("LogEntry_Engine").display = display.hidden;
this.getField("LogEntry_Official").display = display.hidden;
this.getField("Incident_MTF").display = display.hidden;

this.getDataObject("LogEntries").state = false;

TOPICS
Acrobat SDK and JavaScript , Windows

Views

39

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
Community Expert ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

You have multiple errors in your code.

#1:

this.getOCGs("Photos&Diagrams").state = true;

This is not how you access a layer. The getOCGs method returns an array with all the layers. The only parameter it takes is a page number. Once you have that array you can use a for-loop to search it for a specific layer and show/hide it.

#2:

this.getDataObject("LogEntries").state = true;

Data objects don't have a state property, so this line does nothing.

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
Participant ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Thank you for the education.  I had forgotten the get.OCGs was still in place after my unproductive tinkering, I had meant to remove it as the getDataObject was the direction I thought -- clearly incorrectly -- was the way to go.  As it appears neither get.OCGs or getDataObject is the correct answer, is there another means via JS to show and/or hide a specific layer to the exclusion of other layers? 

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
Community Expert ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Using getOCGs is in the right direction, but you have to then process the array it returns as I've described.

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
Participant ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

LOL (at myself), you were over my head dicrectly after your "using getOCGs is in the right direction," comment.  I have no idea at all what constitutes an array in acrobat, let alone how to create one.  Clearly time for some research on arrays. 🙂

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
Participant ,
Nov 04, 2022 Nov 04, 2022

Copy link to clipboard

Copied

LATEST

Thank you for your help.  I finally managed to get it working with the following:

 

var layers = this.getOCGs();
for(var i=0;i<this.layers.length;i++)
{
if (layers[i].name == "Logs")
{
layers[i].state = true;
}
}
getField("LogEntry_Deck").display = display.visible;
getField("LogEntry_Engine").display = display.visible;
getField("LogEntry_Official").display = display.visible;
getField("Incident_MTF").display = display.visible;

 

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