Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Validation Javascript
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Validation Javascript

 Post Reply Post Reply
Author
Barra View Drop Down
New Member
New Member
Avatar

Joined: 19 Feb 2014
Location: Australia
Points: 3
Post Options Post Options   Quote Barra Quote  Post ReplyReply Direct Link To This Post Topic: Validation Javascript
    Posted: 19 Feb 2014 at 11:37pm
Firstly I have no scripting experience and wouldn't mind any suggestion of how I can find someone (online) to work on any script jobs I may have?

Now to the main question:

I have created a PDF portfolio that is made up of PDF fillable forms.  This portfolio is sent to our clients, they fill them out, save them and then send the file back to us.

Someone sent me a script that validates if fields have been answered (changed from default value) and highlights any unchanged fields in red (script is at the bottom of this post).  This has worked fine but it was embedded as a SAVE button at the bottom of each document that was then merged into the PDF portfolio.

Unfortunately this has made the file size unusable (11mb) for how we use them, so we have reverted back to combining all these documents in one PDF (instead of portfolio) and having the clients just use bookmarks to navigate through the length form (it is actually a qualification assessment file).

This means that a document that has 6 pages, where before the first save button would have validated just the first 2 pages and the second save validated the next two pages etc. The save buttons now validate the entire document.

I would like to modify the below script to be able to specify that (for this example) it validates all field names with a 1 at the front (eg 1Dropbox6 or 1Text3).  and then I will embed this code into the second SAVE button but just modify it so that it validates fields that have a 2 in front (2Dropbox6 or 2Text5).  This way each SAVE button will just validate cells in the appropriate pages.

If you would like me to email a copy of the PDF doc please let me know.

function ValueEQDefaultValue() {
   var bResult = false; // assume no errors;
   //If there are, it highlights them with a red border
   for (var i = 0; i < this.numFields; i++) {
    var f =  this.getField(this.getNthFieldName(i));
    var FieldType = f.type; // get field type;
    // test all fields except button and signature;
    if(FieldType !=  "button" && FieldType != "signature" ) {
        f.lineWidth = 0;
        f.strokeColor = color.transparent;
        // see if value has not changed from default value;
        if(f.value == f.defaultValue) {
          // highlight unchanged field
          f.strokeColor = color.red;
          f.lineWidth = 2;
          bResult = true; // report a field not changed;
        } // end value same as default value;
  } // end field type not button or signature;
  if(FieldType == "signature") {
   // enter needed validation here;
}
   } // end field name loop;
     return bResult; // exit function;
   } // end ValueEQDefaultValue

//Checks to see if there are any unchanged fields;
if( ValueEQDefaultValue() ) {
        app.alert("You must fill in all required fields before submitting.");
} else {
// action that all fields passed;
}



Back to Top
Sponsored Links


Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 628
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 20 Feb 2014 at 8:27am
After this line:

var f =  this.getField(this.getNthFieldName(i));

You can add something like this:

if (/^1/.test(f.name)==false) continue; // ignore fields that don't start with "1"
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
mnbarradeen View Drop Down
New Member
New Member


Joined: 30 Aug 2013
Points: 5
Post Options Post Options   Quote mnbarradeen Quote  Post ReplyReply Direct Link To This Post Posted: 20 Feb 2014 at 12:31pm
Mate you are a champion! I don't know how to repay you, my boss gave me till tomorrow to sort this problem out. If it is not pushing the friendship too much a second quick question.

With the same code what would I insert to exclude a specific field from validation. Eg exclude a field called 2Dropdown5.
Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 628
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 20 Feb 2014 at 1:17pm
Add this in the same location more or less:

if (f.name=="2Dropdown5") continue;
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.047 seconds.