• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script for disappearing instructional text in dropdown list

New Here ,
Jan 14, 2025 Jan 14, 2025

Copy link to clipboard

Copied

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!

TOPICS
How to , PDF , PDF forms

Views

273

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Jan 15, 2025 Jan 15, 2025

Copy link to clipboard

Copied

Remove exclamation mark.
Remove color.Gray and replace with this: ["G",0.5 ]

View solution in original post

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2025 Jan 15, 2025

Copy link to clipboard

Copied

event.target.textSize=0;

View solution in original post

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2025 Jan 14, 2025

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2025 Jan 14, 2025

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2025 Jan 14, 2025

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 15, 2025 Jan 15, 2025

Copy link to clipboard

Copied

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;

 

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2025 Jan 15, 2025

Copy link to clipboard

Copied

Remove exclamation mark.
Remove color.Gray and replace with this: ["G",0.5 ]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 15, 2025 Jan 15, 2025

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2025 Jan 15, 2025

Copy link to clipboard

Copied

event.target.textSize=0;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2025 Jan 15, 2025

Copy link to clipboard

Copied

Custom format script should be:

if(event.value == event.target.defaultValue){event.value="Income Type"}

Enter the following custom calculation script:

if(event.value==event.target.defaultValue)
{
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;
}

 

Also, select "Commit selected value immediately" in the Options tab.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 15, 2025 Jan 15, 2025

Copy link to clipboard

Copied

LATEST

Perfect.  This working now, thanks all!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines