Expand my Community achievements bar.

Restrict Printing Until fields are full

Avatar

Level 3

I have form that i only want the user to be able to print if everything is filled out. Is there a code snippet someone can send me of a way to validate the fields and then enable printing. I know it could be in a button, but I want it to not allow them to simple got to File>Print. Like it would be password restricted until the fields were full.

5 Replies

Avatar

Former Community Member

You can make the fields mandatory so that there has to be something in them. Then on the prePrint event you can check to see if there are validations errors or not and if there are errors you can cancel the print. Something like this:

//check to see if there are validation errors

if (form1.execValidate() == true){

     //we have errors so cancel the print

     app.alert("You cannot print until all fields are filled!");

     xfa.event.cancelAction = true;

} else {

     xfa.host.print()

}

Note that you will use a regular button not a print button for this.

Paul

Avatar

Level 3

Okay so this works, however. Now i am forgettting how to set Validation on a textbox. I don't care what they enter as long as it is not Null.

Is there a way to have on the exit something like

If (TextField1.rawvalue == Null) {

TextField1.validate = False;

}

Something like that?

I don't want the textfield to have a set pattern, just not Null

Avatar

Former Community Member

Just go into the Object/Value tab and under the Type change it to User Entered Required.

paul

Avatar

Level 1

I'm trying to do what the topic starter is doing as well (restrict printing until required fields are completed).  I've used something similar to what pguerett suggested in his first post.  I've called a function in the prePrint event of my main form as follows:

form1.Mysubform::prePrint - (JavaScript, client)

{

    if (!ValidationScript.checkForm()) {

        xfa.event.cancelAction = 1;

    }

}

And the function looks something like this:

form1.Mysubform.#variables[0].ValidationScript - (JavaScript, client)

function checkForm() {

    if(form1.Mysubform.MainTable.Row1.Table6.Row1.txtPIname.rawValue==null) {

        xfa.host.messageBox("Please enter PI name");

        return false;

    }

    if(form1.Mysubform.MainTable.Row10.Table12.Row1.newRenewalSubform.rdoNewRenewal.rawValue < 1) {

        xfa.host.messageBox("Please indicate whether this is a new or renewal application.");

        return false;

    }

    else {

        return true;   

    }

}

Basically, if the function's value returned is false, then I set xfa.event.cancelAction = 1, and the user gets a message that identifies the blank field.

This works as described, but only in "recent" versions of Adobe products.  It worked in Adobe Acrobat Professional 8.1.0 and 9.3.3, as well as Adobe Reader 9.0.

Surprisingly, it did not work as intended in Adobe Acrobat Professional 8.2.3 - the user still receives the prompt, but then the print dialog menu appears!  And the same thing happens with Adobe Acrobat Professional 7.0.0 and 7.1.4.

Any ideas as to how to address this issue?  Thanks in advance!

Avatar

Level 10

I just posted this in another thread - here's a post from Stefan Cameron for preventing printing in v8+:

http://forms.stefcameron.com/2008/04/13/prevent-printing-pdf-forms-in-acrobat-8/