Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Feb 20, 2017 Feb 20, 2017

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.

TOPICS
Acrobat SDK and JavaScript , Windows
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 20, 2017 Feb 20, 2017

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

...
Translate
Community Expert ,
Feb 20, 2017 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 20, 2017 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2017 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2017 Feb 20, 2017

Also, there's no need to use a script to do it. You can simply use the built-in Special option under the Format tab, select "arbitrary mask" and enter this as the mask: 999999999

This will only allow the user to enter 9 digits (no more or less) into the field.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 20, 2017 Feb 20, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2017 Feb 20, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2017 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 20, 2017 Feb 20, 2017

Thanks for the answers it helped a lot!

I finally figured it out.

Thanks again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2017 Feb 20, 2017
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines