Skip to main content
Inspiring
Oct 19, 2022 7:33 PM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

5 replies

try67
Community Expert
Community Expert
Oct 19, 2022 7:39 PM UTC

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.

Translate
Inspiring
Oct 19, 2022 7:51 PM UTC

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? 

Translate
try67
Community Expert
Community Expert
Oct 19, 2022 7:54 PM UTC

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

Translate