Java script Help!

Community Beginner ,
May 07, 2020 May 07, 2020

Copy link to clipboard

Copied

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, Comment review and collaborate PDF, Create PDFs, Edit and convert PDFs, General troubleshooting, How to, Install update and subscribe to Acrobat, PDF forms, Print and prepress, Security digital signatures and esignatures, Standards and accessibility

Views

856

Likes

Translate

Translate

Report

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

Adobe Community Professional , 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);

Likes

Translate

Translate
Most Valuable Participant , May 07, 2020 May 07, 2020
Yes, remove that script and add this one instead: if (event.value) event.value = "/" + event.value.replace(/^\//, "").replace(/\/$/, "") + "/";

Likes

Translate

Translate
Most Valuable Participant ,
May 07, 2020 May 07, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

 

 

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Yes, remove that script and add this one instead:

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.png

NDAQ_1-1588883489543.png

 

 

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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