8 Replies Latest reply on May 27, 2015 10:32 PM by jay fresno

    Change field color to red

    jay fresno Level 1

      I have sets of check boxes in an Acrobat form. The user can is required to select one or more of the check boxes in each set. Leveraging off of a previous post by Try67, I was able to create a hidden required text field that alerts users when the click the SUBMIT button if they have skipped the check boxes. This is the custom calculation script used in the hidden text field:

       

      var checkboxes = ["Select First Checkbox","Select Second Checkbox", "Select Third Checkbox", "Select Fourth Checkbox"];

      var v = "";

      for (var i in checkboxes){

      if (v=="" && this.getField(checkboxes[i]).value!="Off")

      v = "OK";

      }

      event.value = v;

       

      That's working great. However, it is difficult for the user to figure out which fields they missed since the check boxes don't turn red like other form fields that are required.

       

      What can I add to this script that would make the check boxes turn red if none of them are checked when the Submit button is clicked -- and is it even possible?

      Would appreciate any help you're able to offer. Thanks.

        • 1. Re: Change field color to red
          jay fresno Level 1

          If this is not possible, I hope someone will let me know so that I don't spend more time trying to solve an insolvable problem. Thanks.

          • 2. Re: Change field color to red
            Karl Heinz Kremer Adobe Community Professional

            You can use the Field.strokeColor property to change the color of the outline of a field. You are already checking to see if the checkbox is checked, and you can use the same construct to also change the stroke color, all you need to do is to add an 'else' branch to reset the color when the checkbox is correctly checked. Something like this should work:

             

            var checkboxes = ["Select First Checkbox", "Select Second Checkbox", "Select Third Checkbox", "Select Fourth Checkbox"];
            var v = "";
            
            for (var i in checkboxes) {
              var f = this.getField(checkboxes[i]);
              if (v == "" && f.value != "Off") {
                 f.strokeColor = color.transparent;  // don't show the outline in any specific color
                 v = "OK";
              }
              else {
                 f.strokeColor = color.red;
              }
            }
            
            event.value = v;
            
            • 3. Re: Change field color to red
              jay fresno Level 1

              khkremer,

              Thank you for your suggestion!

              The code is working to a certain extent.

              What's happening now is that if one or more of the checkboxes are checked, those checked don't turn red, but all the other checkboxes in the group (those that are not checked) do turn red.

              The user is supposed to check one or more of the checkboxes -- if they check at least one, that is enough to satisfy the requirement.


              Is it possible to adjust the code so that if none of the checkboxes are selected they all turn red, and if one or more are selected none of them turn red?

              • 4. Re: Change field color to red
                Karl Heinz Kremer Adobe Community Professional

                Ah, I see. That was a misunderstanding. Go back to you original code, and then insert this snipped after the last line:

                 

                if (v == "OK") {
                 f.strokeColor = color.transparent;  // don't show the outline in any specific color
                }
                else
                {  
                    f.strokeColor = color.red;  
                }
                
                • 5. Re: Change field color to red
                  jay fresno Level 1

                  khkremer,

                  Thank you again!

                  I've changed the code as shown below. I don't know where I'm going wrong, but now all of the checkboxes remain black, whether any of them are checked or not.

                  If none are checked, they should all turn red. If one or more are checked, they should all remain black.

                  Is that possible?

                   

                  var checkboxes = ["Select First Checkbox","Select Second Checkbox", "Select Third Checkbox", "Select Fourth Checkbox"];

                  var v = "";

                  for (var i in checkboxes){

                  if (v=="" && this.getField(checkboxes[i]).value!="Off")

                  v = "OK";

                  }

                  event.value = v;

                   

                  if (v == "OK") {

                  f.strokeColor = color.black;  // show the outline in black color

                  }

                  else

                      f.strokeColor = color.red; 

                  }

                  • 6. Re: Change field color to red
                    Karl Heinz Kremer Adobe Community Professional

                    Sorry, that was my mistake. I should have taken a few more seconds to look at your code. Try this:

                     

                    var checkboxes = ["Select First Checkbox", "Select Second Checkbox", "Select Third Checkbox", "Select Fourth Checkbox"];
                    var v = "";
                    
                    for (var i in checkboxes) {
                      if (v == "" && this.getField(checkboxes[i]).value != "Off")
                        v = "OK";
                    }
                    
                    event.value = v;
                    
                    for (var i in checkboxes) {
                      var f = this.getField(checkboxes[i]);
                      if (v == "OK") {
                        f.strokeColor = color.black; // show the outline in black color
                      } else {
                        f.strokeColor = color.red;
                      }
                    }
                    
                    • 7. Re: Change field color to red
                      jay fresno Level 1

                      khkremer,

                      Many thanks. I think your script would work if there was only one set of required checkboxes.

                      I was trying to keep my post simple, so I didn't explain that I have 2 sets of required checkboxes.

                      What's happening now is that if at least one checkbox is checked in each of the 2 sets, both sets remain black -- that's they way it needs to be, so that's good.

                       

                      However, if one or more checkboxes are checked in just one of the 2 sets, both sets turn red. In other words, both sets of checkboxes are being treated as if they were both part of one set. What should happen is that if one or more checkboxes is checked in one set, and none are checked in the other set, the set with one or more checks remains black but the set with no checks turns red. Is there any way to accomplish that?

                       

                      Yikes. I hope this is understandable. I can send you the form if it would help. Let me know.

                      • 8. Re: Change field color to red
                        jay fresno Level 1

                        khkremer,

                        Thank you for your help. After more work I was able to get the code you provided to change the colors. It is very kind of you to help and to share your expertise.