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

Java script Help!

Community Beginner ,
May 07, 2020 May 07, 2020

I'm trying to create a format for a field in my PDF.

 

Custom Format Script:

event.value="/" +event.value + "/";

 

Custom Keystroke Script:

event.rc = /^[A-Z]*$/.test
(event.change);

 

I'm hoping the outcome that the what ever is entered in this field starts with "/" and ends "/". - when testing for e-sign, it did not warn the signor to use the "/" and "/" and they were able to move to hte next field and sign the document.

 

How can build this script to make it a requirement?

TOPICS
Acrobat SDK and JavaScript
1.8K
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 2 Correct answers

Community Expert , May 07, 2020 May 07, 2020

Delete the format script and move the code to the keystroke script, but it needs to distinguish between the real keystroke and the commit.

 

if(event.willCommit)

     event.value="/" +event.value + "/";

else

     event.rc = /^[A-Z]*$/.test(event.change);

 

 

Translate
Community Expert , May 07, 2020 May 07, 2020

Yes, remove that script and add this one instead:

if (event.value) event.value = "/" + event.value.replace(/^\//, "").replace(/\/$/, "") + "/";

Translate
Community Expert ,
May 07, 2020 May 07, 2020

Do you want the field value to actually have those characters in it, or just to appear as if it does?

If the former then using the Format event will not achieve that. You can use the Validation event to force it.

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 Beginner ,
May 07, 2020 May 07, 2020

I want the field to actually have those characters.  Would I get rid of teh keystroke script and add that to the validation?

 

 

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 Beginner ,
May 07, 2020 May 07, 2020

I meant, do I remove the format script and put that in the validation?*

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 ,
May 07, 2020 May 07, 2020

Yes, remove that script and add this one instead:

if (event.value) event.value = "/" + event.value.replace(/^\//, "").replace(/\/$/, "") + "/";

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 Beginner ,
May 07, 2020 May 07, 2020

Thank you!!! I appreciate it so much, this is a pain!  it still didn't work - i think the issue is trying to fill the form out in adobe e-sign.  could that be an issue?

 

NDAQ_0-1588883457933.pngexpand image

NDAQ_1-1588883489543.pngexpand image

 

 

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 Beginner ,
May 07, 2020 May 07, 2020

My goal is for it to display on the form as:

/John Doe/

and not allow them to move to next field without that format.

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 ,
May 07, 2020 May 07, 2020

Don't use Adobe Sign, and remove the first part of the Keystroke script.

Also, it's not a good idea to "lock" the user into a specific field. I recommend you don't do that.

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 ,
May 07, 2020 May 07, 2020

I would do it the other way around. Leave the keystroke script in place and remove the validation script.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
May 15, 2020 May 15, 2020

Thanks! I actually tried both ways.  It works when in Adobe but does not carry over to e-sign. 

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 ,
May 15, 2020 May 15, 2020

Adobe Sign has very little support for scripts in a PDF file.

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 Beginner ,
May 15, 2020 May 15, 2020
LATEST

Thanks, totally realized this in my testing.  Thanks for the help!

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 ,
May 07, 2020 May 07, 2020

Delete the format script and move the code to the keystroke script, but it needs to distinguish between the real keystroke and the commit.

 

if(event.willCommit)

     event.value="/" +event.value + "/";

else

     event.rc = /^[A-Z]*$/.test(event.change);

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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