These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Validation button to check required fields before signing

jenniferbunecke
Registered: Jul 29 2009
Posts: 35
Answered

There have been a lot of discussions regarding validation scripts, but I can't find any that really fit my needs.

I have a long form with MANY required fields (mainly check boxes). I need a button to validate that all required fields are marked before someone digitally signs the form. I can gray-out, or disable, the signature fields when the user types in the first field. (Thank you Thom for that script! - http://www.acrobatusers.com/tutorials/2007/09/js_disabling_fields) I need a button that would validate all the required fields then enable the signature fields once the validation script passed.

I have found many scripts that will validate fields if emailing or submitting forms, but I need to validate the fields before they are locked-down with a signature.

I am using Windows and Acrobat Professional 8.0

Any help would be greatly appreciated!

My Product Information:
Acrobat Pro 8.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If there are not too many calculation scripts on the form already, you could do validation in real time with a calculation. The Calculation event is called everytime any form field is changed.

One way to do this is to add a Read Only text field next to the Signature field. Then Add a calculation script similar to this:
var bTest = true; var aTestFields = ["Field1", "Field2", ...etc...];var oFld = null;for(var i=0;i<aTestFields.length;i++){var oFld = this.getField(aTestFields[i]);if( ...Field Test Fails...){bTest = false;break;}} if(bTest){event.value = "Form not Ready for Signature";.... Grey out Signature ...}else{event.value = "Form Complete";.... Enable Signature ...}

Of course there are many variations on this kind of validation.
I've got all kinds of examples at www.pdfscripting.com

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

jenniferbunecke
Registered: Jul 29 2009
Posts: 35
Thank you so much Thom... I think we're on to something, and now it's just user error (please bear with me ... )
What do I put in for the ( ...Field Test Fails...) section?

{
var oFld = this.getField(aTestFields[i]);
if( ...Field Test Fails...)
{
bTest = false;
break;
}
}
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Depends on what you want to test. Exactly what are you testing? Do a search on this forum for "conditional calc", you may find what you are looking for.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

jenniferbunecke
Registered: Jul 29 2009
Posts: 35
Thank you for your help.

... however, I have looked through the calc scripts and still can't find excatly what I want...

I have specified a series of conditional checkboxes and normal text fields within the 'aTestFields' variable.

In the next portion of the script I want to say "if [aTestFields] is empty, then fail the validation script."

The required fields include both text boxes and checkboxes with values of either 'yes' or 'no.' Will that matter??

Again I appreciate all your help
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
If any of the text fields are numeric, you have to test their value as a string value. You may also need to adjust for the fact that an unchecked check box has the string value of 'Off'. So I would also check the test field's field type and base my test on what the expected none selected value is.

// set initial stateevent.value = "Form not Ready for Signature";// .... Grey out Signature ... // logical value for passing the required test// assume test passedvar bypassed = true;// array of names for the required fieldsvar aTestFields = ["Check Box1", "Radio Button3", 'Text2', 'Text5'];var oFld = '';for(i = 0;i < aTestFields.length; i++){// get a field objectvar oFld = this.getField(aTestFields[i]);// is this a text fieldif(oFld.type == 'text') {// test value as a stringif(oFld.valueAsString == '') {// value is a null stringbPassed = false; // fail test} // end if null value  } // end if text field has a null value // test for  check boxif(oFld.type == 'checkbox') {if(oFld.value == 'Off') {// value is off so no selection madebPassed = false; // fail test} // end if 'Off'} // end check box type // see if current test failed test      if(!bPassed) {break; // end loop}} // end loop through fields // test if passed testif (bPassed) {event.value = "Form Complete";//  .... Enable Signature ...}

George Kaiser

jenniferbunecke
Registered: Jul 29 2009
Posts: 35
Thank you so much! This is EXACTLY what I needed!!!!