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

Apply format using JS

New Here ,
Nov 27, 2020 Nov 27, 2020

I stumbled upon Karl Heinz Kremer's article called: "Apply Standard PDF Form Field Formatting/Keystroke/Validation Events to Fields via JavaScript".

A button runs this fine:

var f = this.getField("Text2");
f.setAction("Format", "AFNumber_Format(2, 0, 0, 0, \"\", true);");
f.setAction("Keystroke", "AFNumber_Keystroke(2, 0, 0, 0, \"\", true);");

But if the fields contained data before the script is ran and if I manually enter the same value, it does not apply the new format.

Can you help?

Martin

TOPICS
How to
901
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 ,
Nov 29, 2020 Nov 29, 2020

You have to change the data to something else than what it originally was in order for the script to "kick in".

You can even do that in your original code, by adding these lines to the end of it:

var oldValue = f.value;

f.value = "";

f.value = oldValue;

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 ,
Nov 30, 2020 Nov 30, 2020
LATEST

TRY67,

 

Thansk you for your reply.  After I posted the question, I thought of this (almost identical to your suggestion):

 

var f = this.getField("Text2");
var oldValue = f.value
var myDecimals = app.response("decimals?")

f.setAction("Format", "AFNumber_Format(myDecimals, 0, 0, 0, \"\", true);");


f.setAction("Keystroke", "AFNumber_Keystroke(myDecimals, 0, 0, 0, \"\", true);");

f.value= oldValue

 

Martin

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