3 Replies Latest reply on Jan 12, 2011 9:03 AM by gkaiseril

    Validating Spawned page Fields

    MadMich Level 1

      Hi All,

       

      I have a document level script that validates field content when signed. If ok this creates a spawned page of the same document.

      My question is the fields are renamed with the each spawned page no i.e., P1.Field, P2.Field etc., so is it possible to identify these using the same document level script?

       

      At the moment I've had to make templates of each page and rename the fields accordingly.

        • 1. Re: Validating Spawned page Fields
          try67 MVP & Adobe Community Professional

          Since the names of the fields are predictable (like you wrote), then yes,

          you can validate them.

          You can write a loop that tries to get the next field and then check if it

          exists (if not, getField will return null). If so, it validates it. If not,

          it stops.

          • 2. Re: Validating Spawned page Fields
            MadMich Level 1

            Thanks for the fast reply,

            This is my document level script:

             

            function FormComplete() {
            var rFields = new Array(
            ["Field.0",  "Check 1"],
            ["Field.1",  "Check 2"],
            ["Field.2",  "Check 3"],
            ["Field.3",  "Check 4"],
            ["Field.4",  "Check 5"],
            ["Field.5",  "Check 6"],
            ["Field.6",  "Check 7"],
            ["Field.7", "Check 8"],
            ["Field.8", "Check 9"]

             

            // logical value for complexness of form
            var bComplete = true; // assume true

             

            // possible error message
            var errMsg = "";
            // loop through field names in rFields array
            for (i = 0; i < rFields.length; i++) {

             

            // check for empty field
            if (this.getField(rFields[i][0]).valueAsString == "") {
            bComplete = false; // stop submission
            errMsg = errMsg + rFields[i][1] + "\n"; // add field description and new line to errMgt
            this.getField(rFields[i][0]).strokeColor = [ "CMYK", 0,0.5,0.5,0 ]; // highlight the field
            this.getField(rFields[i][0]).value = "N/A"; // Insert N/A value
            }else{
            this.getField(rFields[i][0]).strokeColor =  [ "CMYK", 0,0,0,0.2 ]
            }

             

            } // get next field
            // test if missing field message is needed
            if (bComplete != true) {
            app.alert("Operator must not sign unless all data fields have been completed! \n\n" + errMsg, 1, 1);
            } // end error message needed

             

            return bComplete;
            }

             

            I'm still unsure!

            How do I identify that all  'Fields.0 - 8' are now P1.'Fields.0 - 8? Do I need to revise the document level script or add it elsewhere?

            • 3. Re: Validating Spawned page Fields
              gkaiseril MVP & Adobe Community Professional

              You must have set the 'rename' parameter to true when you spawned the new pages from the template. The newly created form fields will have the page number and the template name appended as a prefix to the field name. The page number will be in the format of  'P#', where # is the JavaScript page number.

               

              PDF templates - the invisible paper by Karl De Abrew

              A Lesson in Templates for Adobe Acrobat by Dave Wright

               

              I would make my template, create a page 1 form from the template and then write my scripts with either the page number as a parameter or the page prefix as the parameter.

               

              Look very carefully at the form field names created on the pages created from the template.