Hi, I would be very grateful for any help with this. I have an 8pg application form, Acrobat9. Almost every field is mandatory and I want the form to not print if an applicant has not filled in a required field.
I have my fields selected 'required' in General properties. I tried to add some script to my print button but no script option appears. Also, on some of my required fields I have java in already so that only numbers can be entered into those fields, so when I go to Advanced Document Processing>document Javascripts... that code is there already and I don't know where to go from here with regard to adding script or whatever is required to do this.
Is there a way that I can add an action to my print button that checks my form fields are completed before it prints off. Also, so my form fields highlight and jumps to the fields that were not completed???
Created form validation script - below.
Set it to run on print and save.
Unfortunately print is not so good - it runs after the printer selection dialog is displayed and does not actually block the printing.
Therefore as a partial fix I added a specific print button.
There is supposedly a working fix using XFA which means using acrobat designer. Supposedly included in acrobat pro for windows. Could possibly work, except as my acrobat is licenced for Mac it is a lot of a hassle.
http://forms.stefcameron.com/2008/04/13/prevent-printing-pdf-forms-in-acrobat-8/
The documentation for acrobat 9 is a bit difficult. The html version online didn't seem to do much for me. I mainly used the 7 reference. It wasn't clear to me that this was the correct reference for 9 http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf and the online stuff mainly says 'javascript syntax is part of javascript' rather than getting on with the acrobat api reference.
Another downfall - these scripts don't run in Mac 'preview'. In fact saving the document gets rid of them completely.
//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------
//
//setDate
//
/*********** belongs to: Document-Level:setDate ***********/
function foundSpecialist()
{
var name = new Array();
var valid = true;
this.addSpecialist = function(specialist)
{
name.push(specialist);
}
this.countSpecialist = function()
{
return name.length;
}
this.resetSpecialist = function()
{
name = [];
}
return true;
}
var specialist = new foundSpecialist();
function validateForm()
{
specialist.resetSpecialist();
findValue("Sydney Metro", specialist);
if (specialist.countSpecialist() == 0) {
app.alert("You forgot to select a doctor. Please select one.");
// var dialogTitle = "Please Confirm";
// var defaultAnswer = "No.";
// var reply = app.response("Did you really mean to type that?",dialogTitle, defaultAnswer);
}
if (!validateNames()) {
app.alert("Did you forget to fill out the name fields?");
}
if (specialist.countSpecialist() > 1) {
app.alert("You selected more than one doctor. Please select only one.");
}
}
function validateNames(specialist)
{
var valid = true;
if (this.getField("Female-partners-given-name").value == '') {
valid = false;
}
if (this.getField("Female-partners-last-name").value == '') {
valid = false;
}
// deliberately not validating male fields.
return valid;
}
// If the field is not the default -- return the value of the field.
function findValue(fieldName, specialist) {
if(this.getField(fieldName).value != "-- Select Doctor --") {
specialist.addSpecialist(this.getField(fieldName).value);
}
}
//
////
//Document Will Save
//
/*********** belongs to: Document-Actions:Document Will Save ***********/
validateForm();
//
////
//Document Will Print
//
/*********** belongs to: Document-Actions:Document Will Print ***********/
app.alert("will print");
validateForm();
//
////
//Print:Annot1:MouseUp:Action1
//
/*********** belongs to: AcroForm:Print:Annot1:MouseUp:Action1 ***********/
validateForm();
if (!validateNames()) {
app.alert("Did you forget to fill out the name fields?");
}
if (specialist.countSpecialist() == 1 && validateNames()) {
this.print({
bUI: false,
bSilent: false,
bShrinkToFit: true
});
}
//
//