Skip to main content
Participant
February 20, 2017
Answered

Need help on validating and printing a PDF document with a button

  • February 20, 2017
  • 3 replies
  • 1616 views

Hello, I have a document which has 2 buttons a send via e-mail, and a print button.

There is a single text input that has to be valideated for a 9 digit number.

I'm using Javascript for the print and email sending and for the validation as well.

My problem is, that the buttons are checking if the field is empty, but if I type in the correct amount of numbers, and DON'T click out of the text field the button will rercieves it as empty thus sending the error message.

Any help would much appreciated. My javascript skills are decent, but I'm not familiar with Adobe JS.

Thank you.

This topic has been closed for replies.
Correct answer Joel Geraci

Can not use the arbitrary mask since all the error messages have to come in German. Here's my code:

On the email button:

mouse-up :

if (this.getField('R.1').value== "" || this.getField('R.1').value == null) {

event.rc=false;

app.alert('Bitte erfassen Sie eine 9-stellige, gültige Partnernummer.');}

else {

this.mailDoc();

}

On print button, mouse down:

if (this.getField('R.1').value== "" || this.getField('R.1').value == null)

{

this.print = false;

app.alert('Bitte erfassen Sie eine 9-stellige, gültige Partnernummer.');}

else {

this.print(true, this.pageNum);

}

My text field has a validation in the validation tab:

if(event.value == null || event.value == "") {

event.rc=true;

}

else

  if(event.value.match(/^(?:(?:[+\-]?(?:(?:0(?:(\.)[0-9]+)?)|(?:[1-9][0-9]*(?:(\.)[0-9]+)?)|(?:(\.)[0-9]+))(?:[eE][\+\-][1-9][0-9]*)?))$/) == null) {

   

event.rc=false;

  }

else if(event.value.length < 9){

event.rc=false;

}

  else {

event.rc=true;

}

I'm a front-end web developer and for some reason my boss thinks if it's JavaScript, I can do it. Well. this isn't the case here.

If you can help me out I would really appreciate it.

Thanks.


The validation script needs to be in the field in question. event.rc doesn't exist for a Button. Also, the value of a text field is never null. An empty field is an empty string. There are examples of how to write validation scripts ALL OVER these forums and in the JavaScript for Acrobat documentation.

And... for what it's worth... if it's JavaScript, you can, in fact, do it. That's all this is, it's just that the object model and how scripts get stored and triggered is different. The core JS is the same.

3 replies

fitomiAuthor
Participant
February 20, 2017

Thanks for the answers it helped a lot!

I finally figured it out.

Thanks again.

Joel Geraci
Community Expert
Community Expert
February 20, 2017

See... you really could do it! Thanks for the star.

Joel Geraci
Community Expert
Community Expert
February 20, 2017

Something is wrong in your order of operations. When a field loses focus... even the mouse down event for the button would cause it... all of the field calculations should run and the value should be set. The only thing I can think of is that your field validator isn't working correctly and is emptying the field regardless of the validation status.

try67
Community Expert
Community Expert
February 20, 2017

When you click the button the value of the text fields gets validated, and if correct, applied to the field, so the required fields validation should work correctly. I just created a form that has the same setup and it worked just fine.

fitomiAuthor
Participant
February 20, 2017

The problem isn't in the validation, the problem is in one particular situation when the user starts to type into the text-box, types a VALID row of numbers, does not click out of it, and directly presses the button to send, for some reason the button receives this as an empty field and throws the error message, on the second click everything works fine, but not on the first. Would it help if I showed the mess of code I did? The field only looks for empty fields for the moment.

Joel Geraci
Community Expert
Community Expert
February 20, 2017

Yes - The code would be handy but the form itself would be even better.

For what it's worth, there just is no way in Acrobat to exit a field by clicking on a button without the value getting committed unless some other bit of code is resetting that value... like a validation script that incorrectly returns a validation failure.