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!
Copy link to clipboard
Copied
Remove exclamation mark.
Remove color.Gray and replace with this: ["G",0.5 ]
Copy link to clipboard
Copied
event.target.textSize=0;
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.
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"]);
Copy link to clipboard
Copied
There is an easier approach, instead of !event.value just check for default value:
event.value == event.target.defaultValue
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;
}
Copy link to clipboard
Copied
Remove exclamation mark.
Remove color.Gray and replace with this: ["G",0.5 ]
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?
Copy link to clipboard
Copied
event.target.textSize=0;
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.
Copy link to clipboard
Copied
Perfect. This working now, thanks all!