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

Conditional Formatting: How to create a "stoplight"

New Here ,
Aug 24, 2021 Aug 24, 2021

Hi everybody,

 

I want to set up a form in which depending if 3 of the criteria are answered with a dropdown "Yes", a text field is filled with a corresponding color and/or text, indicating that all criteria are met (or not).

 

Example:

Verinoca5FD8_0-1629816656410.png

 

I have been playing around with various Javascripts I found in the forums, but none really seemed to work.

 

Do you have any suggestions on how I could solve this? Or how I could at leaset get the answers in the dropdown to change colour depending on the selected answer? 

 

Thank you! 

TOPICS
Windows
1.6K
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

correct answers 2 Correct answers

Community Expert , Aug 24, 2021 Aug 24, 2021

OK, then let's say they're called Dropdown1 to 3. Create a (read-only) text field with the following code as the custom calculation script to achieve what you described:

 

var score = 0;
for (var i=1; i<=3; i++) {
	var f = this.getField("Dropdown"+i);
	if (f.valueAsString=="Yes") score++;
}
if (score==0) event.target.fillColor = color.red;
else if (score<3)  event.target.fillColor = ["RGB", 255/255, 191/255, 0/255];
else event.target.fillColor = color.green;

 

I would also recommend to set the o

...
Translate
Community Expert , Sep 17, 2021 Sep 17, 2021

change: (score ==0) to: (score<=1)

Translate
Community Expert ,
Aug 24, 2021 Aug 24, 2021

So if all the fields are set to Yes it should be green, if any field is set to No it should be amber, and if all are set to No it should be red?

Also, in the screenshot your fields don't look like drop-downs. What actual fields are they?

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
New Here ,
Aug 24, 2021 Aug 24, 2021

So if all the fields are set to Yes it should be green, if any field is set to No it should be amber, and if all are set to No it should be red? // Exactly

 

Also, in the screenshot your fields don't look like drop-downs. What actual fields are they? // The screenshot is made in Excel just for demonstrations purposes. The fields would be Dropdown fields in Acrobat Pro

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 ,
Aug 24, 2021 Aug 24, 2021

OK. Will the fields only have Yes and No as their options? There's no "blank" default option?

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
New Here ,
Aug 24, 2021 Aug 24, 2021
Just yes and no.
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 ,
Aug 24, 2021 Aug 24, 2021

OK, then let's say they're called Dropdown1 to 3. Create a (read-only) text field with the following code as the custom calculation script to achieve what you described:

 

var score = 0;
for (var i=1; i<=3; i++) {
	var f = this.getField("Dropdown"+i);
	if (f.valueAsString=="Yes") score++;
}
if (score==0) event.target.fillColor = color.red;
else if (score<3)  event.target.fillColor = ["RGB", 255/255, 191/255, 0/255];
else event.target.fillColor = color.green;

 

I would also recommend to set the option to commit the selected value of the drop-down fields immediately, which can be found under their Properties, in the Options tab.

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
New Here ,
Aug 26, 2021 Aug 26, 2021

It works! Thank you so much! 

Is it possible to also make the read-only text field which is now the "stoplight" show the colour without having to click on it? Because right now the box is grey/blue, and only "turns" green/orange/red when I click on it.

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 ,
Aug 26, 2021 Aug 26, 2021

Disable the form fields highlighting.

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
New Here ,
Aug 26, 2021 Aug 26, 2021

This only works then for people who have this disabled in Adobe, correct?

Is there a way to set it for all people who receive the PDF?

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 ,
Aug 26, 2021 Aug 26, 2021

Yes, but it will affect all other files they open, so you should at least inform them when you make this change.

In order to do it embed the following code in your file as a doc-level script:

 

app.runtimeHighlight = false;

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
New Here ,
Aug 26, 2021 Aug 26, 2021

All other files that they will ever open, or only the files that they open when this specific file of mine is already open?

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 ,
Aug 26, 2021 Aug 26, 2021

All other files, unless you add another script to your file to set it back to its original state when they close it.

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 ,
Aug 26, 2021 Aug 26, 2021

PS. This should not happen if you set the field as read-only, by the way. Have you done that?

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
New Here ,
Aug 27, 2021 Aug 27, 2021

Ah, I had ticked the wrong box - now it works without the extra script and settings in Adobe.

Thank you so much for your help!!!!

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
New Here ,
Sep 17, 2021 Sep 17, 2021

Hi, small question:

How should the Javascript be if I want the "stoplight" to turn red as well, as soon as two of three options is set to no? Currently it "only" turns red when all three options are no.

Thank you!

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 ,
Sep 17, 2021 Sep 17, 2021

change: (score ==0) to: (score<=1)

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
New Here ,
Sep 17, 2021 Sep 17, 2021
LATEST

Thank you!

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