Skip to main content
Participant
June 3, 2021
Answered

Dropdown box + fill colour dependant on choice

  • June 3, 2021
  • 2 replies
  • 1872 views

Hi,

I am struggling to get my dropdown box fill colour working as required.

I have a dropdown box that the user chooses a colour for a rating.

It sort of works but I would like to change the purple choice to a colour more like purple rather than the magenta I am currently using and the orange choice does not work at all.

This is my code which is in the custom calculation script box:

event.value=this.getField("Input_assurance_rating").value;
if (event.value=="Purple")
event.target.fillColor = color.magenta;
else if (event.value=="Blue")
event.target.fillColor = color.blue;
else if (event.value=="Green")
event.target.fillColor = color.green;
else if (event.value=="Yellow")
event.target.fillColor = color.yellow;
else if (event.value=="Orange")
event.target.fillColor = color.orange;
else if (event.value=="Red")
event.target.fillColor = color.red;
else
event.target.fillColor = color.transparent;
event.target.fontColor = color.transparent;

Thanks

This topic has been closed for replies.
Correct answer Nesa Nurani

You can't set font color to transparent and it should be textColor not fontColor.

There is no color.orange, you need to use other methods for example convert hex code colors and divide it by 255, for example: hex code for color purple 90 0 90 so code would be ["RGB", 0.35, 0, 0.35]

2 replies

Participant
December 15, 2023

@Nesa Nurani @Dave5FF3 

Hello both, I am running the same script adapted to my needs. Unfortunately, when I preview my form the colors do not stick. Can one of you assist? 

 

 

I use the script below and pasted it in run custom validation script.

 

if (event.value=="Complete")

event.target.fillColor = color.green;

else if (event.value=="In_Progress")

event.target.fillColor = color.yellow;

else if (event.value=="Issue")

event.target.fillColor = color.red;

Nesa Nurani
Community Expert
Community Expert
December 15, 2023

Go to Preferences → Forms and uncheck 'Show border color for fields'.

Participant
December 15, 2023

wow do I feel dumb! thank you!

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
June 3, 2021

You can't set font color to transparent and it should be textColor not fontColor.

There is no color.orange, you need to use other methods for example convert hex code colors and divide it by 255, for example: hex code for color purple 90 0 90 so code would be ["RGB", 0.35, 0, 0.35]

Dave5FF3Author
Participant
June 3, 2021

Thank you Nesa,

I have tweaked the code and would now like to have a black coloured font for two of the coloured options and I now get a syntax error 9 on line 10.

event.value=this.getField("Input_assurance_rating").value;
if (event.value=="Purple")
event.target.fillColor = ["RGB", 0.35, 0, 0.35];
else if (event.value=="Blue")
event.target.fillColor = color.blue;
else if (event.value=="Green")
event.target.fillColor = color.green;
event.target.textColor = color.black;
else if (event.value=="Yellow")
event.target.fillColor = color.yellow;
event.target.textColor = color.black;
else if (event.value=="Orange")
event.target.fillColor = ["RGB", 0.81, 0.43, 0];
else if (event.value=="Red")
event.target.fillColor = color.red;
else
event.target.fillColor = color.white;
event.target.textColor = color.white;

Do you know the cause?

Thanks in advance

Nesa Nurani
Community Expert
Community Expert
June 3, 2021

In few conditions you have two lines which needs to be inside curly brackets.

example:

else if (event.value=="Green"){
event.target.fillColor = color.green;
event.target.textColor = color.black;}