8 Replies Latest reply on Mar 22, 2011 12:09 PM by BellsyTO2

    Acrobat Validation Script

    BellsyTO2

      Hi,

       

      I am a designer, not a developer. Code is not my language. I have a question that is probably pretty easy, but I need help. Here is what I want to do:

       

      Form field 1 = Patients

      User fills in a number of patients

       

      For the next form field I want to limit the number that the user can enter to the number they have entered in "Patients". So the number cannot exceed the number entered in the first form field ("Patients").

       

      Can anyone help with the code for the custom validation script??

       

      Many Thanks!

        • 1. Re: Acrobat Validation Script
          George_Johnson MVP & Adobe Community Professional

          You would have to use a Validate script for the second field, something like:

           

          // Custom Validate script
          (function () {
          
              // Get the value in the Patients field, as a number
              var v1 = +getField("Patients").value;
          
              // Get this field value, as a number
              var v2 = +event.value;
          
              // Test if this field value is greater than the number of patients
              if (v2 > v1) {
          
                  // Alter the user to the error
                  app.alert("Value must be less than the number of patients. Please correct.", 1);
          
                  // Reject the value that the user entered
                  event.rc = false;
              }
          
          })();
          
          
          • 2. Re: Acrobat Validation Script
            BellsyTO2 Level 1

            Thanks a ton George!

             

            I understand your logic, but it doesn't seem to be working. Here is what I have:

             

            (function () {

                var v1 = +getField("Patients").value;

                var v2 = +event("Ex1").value;

             

                if (v2 > v1) {

                    app.alert("Value must be less than the number of patients. Please correct.", 1);

             

                    event.rc = false;

                }

             

            })();

            • 3. Re: Acrobat Validation Script
              George_Johnson MVP & Adobe Community Professional

              var v2 = +event("Ex1").value;

               

               

              That should be as I posted, which is:

               

               var v2 = +event.value;
              
              • 4. Re: Acrobat Validation Script
                BellsyTO2 Level 1

                Thanks for all your help! This worked.

                 

                Client has thrown a curve ball however. Here is the situation.

                 

                I have 5 rows. The sum of each row cannot exceed the number of "Patients".

                 

                As soon as one row exceeds the limit, I get the dialogue message no matter what row I am typing in, until the problem row is fixed.

                 

                Is there anyway to separate the rows so they are not connected?

                • 5. Re: Acrobat Validation Script
                  George_Johnson MVP & Adobe Community Professional

                  You need to explain more about how the form is set up. Post the code you're using and explain exactly where it is placed.

                  • 6. Re: Acrobat Validation Script
                    BellsyTO2 Level 1

                    Sorry, I should have been more clear.

                     

                    This is a screen shot of the table setup:

                     

                    Screen shot 2011-03-22 at 2.08.04 PM.png

                     

                    The small form fields at the end of each row are set to calculate the sum of each row individually (PARow1, PARow2, PARow3, PARow4, PARow5). The sum total of each row cannot exceed the number of "Patients" (see form field titled "Patients").

                     

                    Each form field for the sum of each row (ex. PARow1) have the code that was supplied earlier inserted in the "Run custom validation script" box:

                     

                     

                    (function () {

                        var v1 = +getField("Patients").value;

                        var v2 = +event.value;

                     

                        if (v2 > v1) {

                            app.alert("The total sum of the row must be less than or equal to the number of patients. Please correct.", 1);

                     

                            event.rc = false;

                        }

                     

                    })();

                     

                     

                     

                     

                     

                    Problem: Anytime a row (ex. PARow1) exceeds the number of "Patients", the diaglogue box appears no matter what row you are typing in (ex. PARow2).

                     

                    Just because PARow1 is over the limit, does not mean ALL rows are over. Is there a way to isolate each row so they are independent of each other?

                     

                    I hope this is clear.

                    • 7. Re: Acrobat Validation Script
                      George_Johnson MVP & Adobe Community Professional

                      So each of the row total fields also has a calculate script or uses one of the built-in methods, correct? If you're using a custom calculate script, can you post it?

                      • 8. Re: Acrobat Validation Script
                        BellsyTO2 Level 1

                        Yes, it is using a built-in method. No script.