10 Replies Latest reply on Nov 20, 2015 2:42 AM by try67

    Change fill color in drop down menu based on input

    agauvin57 Level 1

      Hello everyone,

       

      I have a PDF document that I'm currently working with and having trouble creating one of the elements. This document is a quarterly status report. It has boxes for Indicators, Data Sources, etc.

       

      The last field is just called "Status". I turned this field into a drop-down menu with 3 options - In Progress, Needs Review, Completed. I would like the user to be able to select one of these options from the drop down menu and have the fill color of the box (field) change based on their selection. If they select "In Progress" the box changes to yellow, "Needs Review" the box changes to red, "Completed" the box changes to green. Because this document will be used by many people, the colors will provide a quick snapshot as to which projects/activities are on task and which needs to be addressed.

       

      Again, based on their selection:

      "In Progress" = yellow

      "Needs Review" = red

      "Completed" = green


      The background color can be white or transparent when no options are selected.

       

      I've been searching and have found a few examples, but nothing close to what I'm looking for. Is this possible to do, and could someone please provide the custom validation script? I know this option is easy and available in Excel, unfortunately there's no smooth way to convert the document without hours of clean up.

       

      I appreciate any help!

        • 1. Re: Change fill color in drop down menu based on input
          try67 MVP & Adobe Community Professional

          Here you go:

           

          if (event.value=="In Progress")
              event.target.fillColor = color.yellow;
          else if (event.value=="Needs Review")
              event.target.fillColor = color.red;
          else if (event.value=="Completed")
              event.target.fillColor = color.green;
          else event.target.fillColor = color.white;
          

           

          To make it work smoothly make sure to tick the option (under Properties - Options) to commit the select value immediately.

          • 2. Re: Change fill color in drop down menu based on input
            agauvin57 Level 1

            YOU ARE AMAZING! Thank you so much for your help! The script worked perfectly.

            I really, really appreciate your help.

            • 3. Re: Change fill color in drop down menu based on input
              BSisson Level 1

              I tried a different approach using the SWITCH command, but nothing changed.

              I put in lots of debug, and everything looks good, but the pulldown box never changes....

              What am I missing??

               

              {
              console.println("Entering colortest switch routine");
                var incomming = event.target.value;
                var Field = event.target;
                console.println(" Incomming value chosen was: "+incomming);
                console.println(" The field we are trying to color is: "+Field.name);

                switch (incomming)
                {
                case "NA" :
                      console.println(" NA");
                      Field.fillcolor = color.black;
                      break;
                case "Hazzard" :
                      console.println(" Hazzard");
                      Field.fillcolor = color.red;
                      break;
                case "Defective" :
                      console.println(" Defective");
                      Field.fillcolor = color.black;
                      break;
                case "Servicable" :
                      console.println(" Servicable");
                      Field.fillcolor = color.black;
                      break;
                case "Marginal" :
                      console.println(" Marginal");
                      Field.fillcolor = color.orange;
                      break;
                case "NI" :
                      console.println(" NI");
                      Field.fillcolor = color.black;
                      break;
                }
              }

              ---------------------------------------------

              console results

              Entering colortest switch routine

              Incomming value chosen was: NA

              The field we are trying to color is: SectionStatus

              NA

              Entering colortest switch routine

              Incomming value chosen was: Servicable

              The field we are trying to color is: SectionStatus

              Servicable

              Entering colortest switch routine

              Incomming value chosen was: Hazzard

              The field we are trying to color is: SectionStatus

              Hazzard

              Entering colortest switch routine

              Incomming value chosen was: NI

              The field we are trying to color is: SectionStatus

              NI

              • 4. Re: Change fill color in drop down menu based on input
                Bernd Alheit Adobe Community Professional & MVP

                Use fillColor, not fillcolor.

                • 5. Re: Change fill color in drop down menu based on input
                  avalonpp Level 1

                  Hi There: I'm trying to do the same thing as was described in the original post, but for some reason it is not working for me. Please let me know if any of the following things  might be messing me up. I have a drop down list that has 4 options. The default is "Select" and that background should be yellow. Other options are "Yes" which should make the background green, "No", which should make the background red, "Maybe" which make the background grey.

                   

                  Under the General tab, Name is "Select"

                  Appearance: No border, white fill (transparent is unchecked), black text,

                  Options:

                  Item: Select

                  Export Value is blank

                  Item List: Select, Yes, No, Maybe

                  Only "Commit Selected Value Immediately" is checked.

                   

                  Actions is blank

                   

                  Validate has "Run Custom Validation Script" checked

                  This is what I put in.

                   

                  if (event.value==“Select”) 

                  event.target.fillColor = color.yellow; 

                  else if (event.value==“Yes”) 

                  event.target.fillColor = color.green;

                  else if (event.value==“No”) 

                  event.target.fillColor = color.red;  

                  else if (event.value==“Maybe”) 

                  event.target.fillColor = color.grey; 

                  else event.target.fillColor = color.white;

                   

                  After all that, then 2 things:

                  1. Does anyone see anything wrong

                  2. If I get this working can I use hex code to denote a color instead of just red or green, etc.

                  • 6. Re: Change fill color in drop down menu based on input
                    try67 MVP & Adobe Community Professional

                    1. The code looks fine. Are there any error messages in the JS Console? What happens when you change the value? Does it remain white?

                    2. Yes, you can specify specific colors, but not with hex code. You can do it using numeric RGB or CMYK or Grayscale values. I can explain further, if you wish.

                    • 7. Re: Change fill color in drop down menu based on input
                      avalonpp Level 1

                      There aren't any error messages in the console. Basically,  no matter what I do, the background is always white.

                      I made a quickie test document just to try to figure it out.

                      Is there a way I can attach it or send it to you? Maybe if you look at it something will jump out at you.

                      And yes, once I get it working, I would like to be able to specify colors using RGB values.

                      • 8. Re: Change fill color in drop down menu based on input
                        try67 MVP & Adobe Community Professional

                        You can upload it to a file-sharing website (dropbox, google drive, etc.) and post a link to it here, or if you want you can email it to me directly at try6767 at gmail.

                        • 9. Re: Change fill color in drop down menu based on input
                          avalonpp Level 1

                          Thanks, emailing now

                          • 10. Re: Change fill color in drop down menu based on input
                            try67 MVP & Adobe Community Professional

                            For others reading this thread, the issues were:

                            - Wrong kind of double-quotes used in the code

                            - Use of an invalid code object (color.grey instead of color.gray).