Skip to main content
Inspiring
October 19, 2022
Question

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

  • October 19, 2022
  • 1 reply
  • 561 views

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;

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
October 19, 2022

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.

Inspiring
October 19, 2022

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? 

try67
Community Expert
Community Expert
October 19, 2022

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