Skip to main content
Participant
January 14, 2025
Answered

Script for disappearing instructional text in dropdown list

  • January 14, 2025
  • 2 replies
  • 1077 views

Hi all,

 

Would someone be so kind as to supply some code for displaying disappearing instructional text in a dropdown list?  I've found plenty of guidance for code that works with text fields, but nothing substantial for dropdown lists.  I'm not a coder, I'm a copy and paster 😀.   I tried adapting the text field examples to my drop down lists, but it negates any selections made from the list, so I'm assuming I need different code to accomplish this.  Thanks in advance!

Correct answer PDF Automation Station

Thanks!  This solved the main issue, selections are sticking as intended.

 

The only thing that's not quite right is that when making a selection from the dropdown, I was hoping the resulting font size could be auto sized.   At the end of the code, is there something I can replace the font size 8 with to instead auto size the choice to fit the box?


event.target.textSize=0;

2 replies

PDF Automation Station
Community Expert
Community Expert
January 15, 2025

Enter the following script as a custom format script:

if(!event.value){event.value="Instructional Text"}

Keep in mind that the first entry in the list needs to be null for this to work.  You can only do that by running the setItems method on the field.  Example:

this.getField("Dropdown").setItems(["","AA","BB","CC"]);

Nesa Nurani
Community Expert
Community Expert
January 15, 2025

There is an easier approach, instead of !event.value just check for default value:
event.value == event.target.defaultValue

Mborkow31Author
Participant
January 15, 2025

Could I trouble you to correct my code?  I'm not sure how to implement your suggestion.  Also, is there a way when deferring to the selected item from the dropdown list to also defer back to the standard font size and color?  In this instance, I have the size set to auto.  

 

thanks so much.

 

if (!event.value==" ") {

 

    event.value = "Income Type";

 

    event.target.display = display.noPrint;

 

event.target.textColor = color.Gray;

 

event.target.textSize = 4;

 

} else {

 

    event.target.display = display.visible;

 

event.target.textColor = color.black;

 

event.target.textSize = 8;

 

}

try67
Community Expert
Community Expert
January 14, 2025

It should work, but you have to tick the box that says "Allow Custom User Input" under the field's Properties, in the Options tab.