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

Custom format script

New Here ,
Oct 06, 2021 Oct 06, 2021

How correctly set custom format script for newly created text field?

I tried f.setAction("Format", "my_script"). No error shows after creating my text field, but nothing appears in custom format field box for that field. I cannot figure out what is missing. Cannot find anything relevant online. Script itself works fine. Please help. Thank you very much in advance.

TOPICS
How to , JavaScript , PDF forms
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
Community Expert ,
Oct 06, 2021 Oct 06, 2021

f is undefined.

 

Try:

this.getField("FIELD-NAME").setAction("Format", "my_script");


Acrobate du PDF, InDesigner et Photoshopographe
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 06, 2021 Oct 06, 2021

Of course f is defined, I just haven't shown that. All code works, I just cannot find details/instructions about that setAction("Format", ...) line.

In other place I have f.setAction("Keyword", "my_script") and it is working 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 ,
Oct 06, 2021 Oct 06, 2021

excuse me, "Keystroke"

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 ,
Oct 06, 2021 Oct 06, 2021

What's the actual code you used for the format script itself?

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 ,
Oct 07, 2021 Oct 07, 2021

All details/instructions are here in the SDK:

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/html2015/Acro12_MasterBook/JS_API_AcroJS...


Acrobate du PDF, InDesigner et Photoshopographe
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 ,
Oct 07, 2021 Oct 07, 2021

How does you test the script?

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 07, 2021 Oct 07, 2021

Just to be clearer: When creating a new text field, I want to add custom format script. I can easily do that when field already exist using Acrobat custom format option. However, when I tried to do that using js f.setAction("Format", "my_script") like shown in the manual, there is no action. This line is just ignored and nothing appear in my new text field property custom format window. I cannot understand why is that.

May be Thom Parker knows why if he is still there :).

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 ,
Oct 07, 2021 Oct 07, 2021

> I can easily do that when field already exist using Acrobat custom format option. 

 

What does you enter there?

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 07, 2021 Oct 07, 2021

I can enter there any JS, such as getField("Test").value = 1 and it works. But using setAction("Format", "getField("Test").value = 1") doesn't work. Very strange.

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 ,
Oct 07, 2021 Oct 07, 2021

Check the Javascript console for errors.

You must use \" in text strings, not only "

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 ,
Oct 07, 2021 Oct 07, 2021

Is your field name correctly in f variable?

Can you post full script you use?

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 07, 2021 Oct 07, 2021
LATEST

Thank you guys, of course that was my fault.

I just have two f. text fields and all the time tried to apply my script to the wrong field.

Everything works like intended 🙂

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