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

Custom Format Script. Go to new line when full utilizing copy and paste method.

Guest
Dec 04, 2019 Dec 04, 2019

Hello Everyone,

 

I have created two form lines.  First one is tagged "PurposeOtherDetails01" and the second "PurposeOtherDetails02". Within the first tag - properties - format, I created a custom script: 

 

if(event.willCommit||event.fieldFull) {this.getField("PurposeOtherDetails02").setFocus();}

 

This should push my text into the second line form when the first one is full, which works fine.  I am, however, running into an issue when copying and pasting into the form rather than typing it out.  You can see from my screenshot below it cuts off and does not go to the next line.  Does anyone have a solution?  

 

2019-12-04_13-09-32.jpgexpand image

Side note: I am using the copy and paste method because a user will be entering details in a different UI and the software will map it onto the PDF.

 

Thanks!

TOPICS
Acrobat SDK and JavaScript
8.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
Community Expert ,
Dec 04, 2019 Dec 04, 2019

So this is a custom keystroke script? not a format script.  

The script only changes the keyboard focus when the user is typing and reaches the entry limit, or hits the return key. It does not split the string.  Pasting text, or importing text into a form field does not simulate the user typing, which is the only way this script works. To handle pasting long text the script needs to use event.change and event.changeEx to perform the split. 

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
Guest
Dec 04, 2019 Dec 04, 2019

Hey Thom_Parker,

 

Yes this is a custom keystroke script.  I tried your method:

 

if(event.change&&event.changeEx) {this.getField("PurposeOtherDetails02").setFocus();}

 

And it is still failing. Any other functions you'd recommend to try or if I should modify my script?

 

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
Guest
Dec 04, 2019 Dec 04, 2019

Also tried if(event.change||event.changeEx) {this.getField("PurposeOtherDetails02").setFocus();}

the "or" and it does not work.

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 ,
Dec 04, 2019 Dec 04, 2019

I think you've missed my point. You actually have to write code to split the string and place the extra text into the other field. Your original code was copied from the Acrobat JavaScript reference. At the same location in the reference the significance of event.change and event.changeEx is explained. 

 

Do you have any experience writing code? This particular issue of automatically splitting text between fields is a thorny one with no good overall solutions. So, this is a bit of an advanced scripting task.

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
Guest
Dec 04, 2019 Dec 04, 2019

I got your point after I thought about it a little bit.  Yes I do have experience writing code but yes, this one is a little tricky.

 

Thanks for your 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 ,
Dec 04, 2019 Dec 04, 2019

Here is an article on string manipulation:

https://acrobatusers.com/tutorials/splitting-and-rebuilding-strings

 

You'll find more info on scripting Acrobat here:

https://www.pdfscripting.com/public/main.cfm

 

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
New Here ,
Oct 20, 2023 Oct 20, 2023
LATEST

Hi Phitranpt,

Were you able to figure out how to go to the next line when copying and pasting?

Thanks,

Laura

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 ,
Dec 05, 2019 Dec 05, 2019

Stop. Back away slowly. Don't make any sudden movements.

 

I've been trying to get that concept to work for over a decade. You can't. You can certainly get it working under certain ideal conditions but reliably flowing text between fields and allowing for typing, copy/paste, selecting across the fields, backspacing across fields... is just impossible in any practical sense.

 

I suggest you rethink your solution.

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 ,
Dec 05, 2019 Dec 05, 2019

Absolutely true, but hey, maybe he doesn't need it to work in all situations. I mean why did Adobe provide a partial solution. Even putting code in the JS Ref for it. They must have though this was good enough, so who am I to disabuse people of the notion 😉

 

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 Expert ,
Dec 05, 2019 Dec 05, 2019

Don't use 2 fields. Use one multi-line 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 ,
Apr 16, 2021 Apr 16, 2021

I was able to do this with a set of scripts.

First script, on 'got focus', joins the text from both fields, assigns it to the field you clicked on and blanks the other field.

Second script, on 'blur', determines how to split the script back into the 2 fields.

 

I used it for a form we had to create that came from another agency.  We couldn't change the form (which had several fields too small for what needed to be typed) but we could add attached pages.  When a field over-ran, it flowed to the attachment.  But you can click either on the original field, or the overflow field, to edit.

I can't share the original due to confidentiality, but the attached page has 2 sets of flowing fields. 

 

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