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

How to apply different colors to different items in a list

New Here ,
May 29, 2023 May 29, 2023

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.

 

 

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms
904
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
May 29, 2023 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
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 ,
May 29, 2023 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
May 29, 2023 May 29, 2023
LATEST

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;
	}
}

@+

Translate
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