Skip to main content
Participant
May 29, 2023
Answered

How to apply different colors to different items in a list

  • May 29, 2023
  • 2 replies
  • 1026 views

Dear community,

 

I've tried to find a solution on the forum but haven't found an answer. So, this time I need help creating a drop down list. I want this menu to have a list of 16 different RAL pallet colours that my customers will be able to select (only 1 of them) when filling out the offer form. I want to help them and make all these colours visible from the drop down list before and after they make their decision. What I mean is, is it possible to make it so that when the list of colours is expanded, each of them has "its" colour assigned to the background? And so that when you select it from the list, it appears as selected along with the assigned background colour.

 

At the moment I made short combo box with list of 3 colors (yellow - 1021 / red - 3020 / green - 6018) and I'm trying with:

"

switch(event.value)

{

case "1021":

event.target.fillColor = color.yellow;

break;

case "3020":

event.target.fillColor = color.red;

break;
case "6018":

event.target.fillColor = color.green;

break;

}"

 

 but it affects the color of the entire list, not a specific color selection, and it's not visible when selected.

 

 

This topic has been closed for replies.
Correct answer Thom Parker

Items in a list field cannot be different colors. 

However, individual fields could be put together to look like a dropdown list. Button fields would work best.

 

  

2 replies

bebarth
Community Expert
Community Expert
May 29, 2023

Hi,

Here is a file with a script I did some times ago if that can help you.

RAL values come from wikipedia, I didn't check if they are all correct.

if (!event.willCommit) {
	if (event.changeEx!="0") {
		var couleur=event.changeEx.split(";");
		this.getField("theColor").value=couleur[0].toUpperCase();
		var laCouleur=["RGB",couleur[1]/255,couleur[2]/255,couleur[3]/255];
		this.getField("theColor").fillColor=["RGB",couleur[1]/255,couleur[2]/255,couleur[3]/255];
		var leNoir=color.convert(laCouleur, "G");
		if (leNoir[1]<.5) this.getField("theColor").textColor=color.white;
		else this.getField("theColor").textColor=color.black;
	} else {
		this.getField("theColor").value="";
		this.getField("theColor").fillColor=color.transparent;
	}
}

@+

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
May 29, 2023

Items in a list field cannot be different colors. 

However, individual fields could be put together to look like a dropdown list. Button fields would work best.

 

  

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often