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

Conditional Formatting: How to create a "stoplight"

New Here ,
Aug 24, 2021 Aug 24, 2021

Copy link to clipboard

Copied

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

Views

112

Likes

Translate

Translate

Report

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

...

Likes

Translate

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

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

Likes

Translate

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

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Just yes and no.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Disable the form fields highlighting.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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;

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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!!!!

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thank you!

Likes

Translate

Translate

Report

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