Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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