Toggle Image Field Visibility with List Box
- September 10, 2020
- 2 replies
- 1357 views
Hello Adobe Community. Long time reader, first time posting here.
I have a List Box that I am using to change information in a large number of text fields via a function containing an array in a Document Script. These fields pertain to the spec values for different products (voltage, amperage, weight, etc), so whenever we stock a new product to the list, this has been extremely easy to add the info to the array and as an option in the List Box.
Here's an abbreviated version of the script as an example:
var modList = {
LG420: { module: "LG LG420N2W-V5", wattage: "420", voc: "49.7", vmp: "42.1", isc: "10.63", imp: "9.98", ptc: "386.9", length: "79.7", width: "40.3", weight: "47.81", POmod: "505", MaxinDC: "17.5", MaxinV: "83", MaxoutA: "15", Maxoutv: "85" },
LG400: { module: "LG LG400N2T-J5", wattage: "400", voc: "49.7", vmp: "41.5", isc: "10.22", imp: "9.65", ptc: "366", length: "79.7", width: "40.3", weight: "47.81", POmod: "505", MaxinDC: "17.5", MaxinV: "83", MaxoutA: "15", Maxoutv: "85" },
};
function Inheritance(modProps) {
this.getField("Module").value = modList[modProps].module;
this.getField("ModW").value = modList[modProps].wattage;
this.getField("sld.Str1.ModW").value = modList[modProps].wattage;
this.getField("sld.Str1.VOC").value = modList[modProps].voc;
this.getField("sld.Str1.VMP").value = modList[modProps].vmp;
this.getField("sld.Str1.ISC").value = modList[modProps].isc;
this.getField("sld.Str1.IMP").value = modList[modProps].imp;
this.getField("sld.Str1.POmod").value = modList[modProps].POmod; this.getField("sld.Str1.MaxinDC").value = modList[modProps].MaxinDC; this.getField("sld.Str1.MaxinV").value = modList[modProps].MaxinV; this.getField("sld.Str1.MaxoutA").value = modList[modProps].MaxoutA; this.getField("sld.Str1.Maxoutv").value = modList[modProps].Maxoutv;
this.getField("PTC").value = modList[modProps].ptc;
this.getField("ModLength").value = modList[modProps].length;
this.getField("ModWidth").value = modList[modProps].width;
this.getField("ModWeight").value = modList[modProps].weight;
}
This script is run on Selection Change;
if( event.willCommit ) {
if(event.value == "") this.resetForm(["sld.Str1.Module","sld.Str2.Module","sld.Str3.Module"]); else Inheritance(event.value)
}
I have also been using this same List Box to control Layer Visibility for the product specification sheets. This is programmed with a MouseUp action in the List Box properties, which calls another Document Script using the getOCGs function:
function ctrlLayers()
{
// get the radio button state
var sel = this.getField("modList").value;
var ocgs = this.getOCGs();
for (i=0; i < ocgs.length; i++) {
ocgs[i].state = (ocgs[i].name == sel);
}
}
I have recently encountered issues with the Visibility script, namely that it has stopped working. I cannot fathom why it stopped, seemingly out of the blue. Changing the selection in the List Box still flawlessly changes all of the spec values, but the visibility of the layers seems to be dependent on whichever option is last in the List Box.
My previous method to achieve the same results involved using Buttons to change all of the field values and control the visibility of images containing the spec sheet pages. However, as my form became more complex and many more text fields were added, it became increasingly difficult to add new products, as every line of the code needed to be changed individually.
I would like to continue to use the List Box method to control the contents of the text fields, but also return to using Images instead of Layers for the spec sheets. Unfortunatley, I am at a loss to figure out how to control the visibility of Image fields depending on the Selection Change in the List Box.
Ideally, the output value of the List Box would be passed to a document script which recognizes the value and sets the visibility of the approprate image to Visible, which otherwise would be Hidden. Maybe an if/else conditional?
Alternatively, if it is possible to add a script to the Image field to receive the output value of the List Box and set itself to Visible as a conditional, that would work too, I suppose.
I imagine that the answer to this may be extremely simple, to which I admit that the majority of my (extremely limited) knowledge on this subject has been due in large part to this forum and Thom Parker's website (SHOUTOUT!).
Any help would be very much appreciated!
