Skip to main content
Participant
Jan 14, 2025 10:31 PM UTC
Answered

Script for disappearing instructional text in dropdown list

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!

PDF Automation Station
Community Expert
Jan 15, 2025 3:55 PM UTC

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;

9 replies

PDF Automation Station
Community Expert
Community Expert
Jan 15, 2025 12:44 AM UTC

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"]);

Translate
Nesa Nurani
Community Expert
Community Expert
Jan 15, 2025 5:52 AM UTC

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

Translate
Mborkow31Author
Participant
Jan 15, 2025 2:40 PM UTC

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;

 

}

Translate
try67
Community Expert
Community Expert
Jan 14, 2025 10:55 PM UTC

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.

Translate