I'm not sure if the is the right place to post my question I've posted it under forms <http://forums.adobe.com/thread/996327> with no success hoping that someone might be able to help me here:
I have the same question as this thread <http://forums.adobe.com/thread/756410> plus a little bit extra.
So the answer (which has worked out wonderfully) was submitted by George:
// Custom format script for text field
if (!event.value) {
event.value = event.target.userName;
event.target.display = display.noPrint;
} else {
event.target.display = display.visible;
}
But as George eluded in his first post in the thread was:
The problem with this approach is it precludes easily using any of the built-in formats that you may want to use (Number, ZIP code, etc.). You still can, but it requires more scripting.
So how can I get the combination of the Form Field Lable being displayed and also the auto formatting for Phone numbers, Zip Codes etc.?
Any help is greatly appreciated.
I'm running Acrobat X Pro on Windows if that matters.
Message was edited by: chad Snelson
Updated question:
So I was thinking about it some more and remembered seeing this line of code:
event.value = util.printx("99-9999999", event.value); From <http://forum.planetpdf.com/wb/default.asp?action=9&fid=34&read=43365>.
And then the Arbitrary Mask formatting option
<http://help.adobe.com/en_US/acrobat/standard/using/WS58a04a822e3e50102 bd615109794195ff-7de4.w.html>
and it appears that the tax id line of code uses those same guide lines. So is there away to use George's section of code and combine it with the tax id line of code and just use the Arbitrary Mask formatting rules so if one text field was for a zip use George's section and just change the tax id line so instead of all the nines it would just have 99999 ? If this makes any sense or is possible if someone could please reply with an example I'd greatly appreciate it!
So I was playing around with combining both soultions and just added the Tax ID formatting to George's part and came up with this:
// Custom format script for text field
if (!event.value) {
event.value = event.target.userName;
event.target.display = display.noPrint;
} else {
event.target.display = display.visible;
event.value = util.printx("99-9999999", event.value)
}
So that works great if you put in a total of nine numeric characters but if you input letters then it still lets you it just doesn't show them verses the arbitrary mask formatting option where it doesn't even let you put in letters and requires the right about of numeric characters.
So my new question/problem is how to only allow numeric characters to be entered and require the right ammount of characters with the above code?
If you can find a copy of the Version 5 Acrobat JS API. There is reference to some internal JS functions for keystrokes, and format.
AFNumber_Format()
AFNumber_Keystroke()
AFPercentage_Format()
AFPercentage_Keystroke()
AFDate_FormatEx_Format()
AFDate_FormatEx_Keystroke()
AFTime_Format()
AFTime_Keystroke()
AFSpecial_Format()
AFSpecial_Keystroke()
You can list the code in the JS console by removiing the "()" and see the parameters needed to call the funciton.
AFSpecial_Format
function AFSpecial_Format(psf) {
var value = event.value;
if (!value) {
return;
}
switch (psf) {
case 0:
var formatStr = "99999";
break;
case 1:
var formatStr = "99999-9999";
break;
case 2:
var NumbersStr = util.printx("9999999999", value);
if (NumbersStr.length >= 10) {
var formatStr = "(999) 999-9999";
} else {
var formatStr = "999-9999";
}
break;
case 3:
var formatStr = "999-99-9999";
break;
default:;
}
event.value = util.printx(formatStr, value);
}
So how or where would I implement that code? In each field?
Right now this is pretty much what I have for each field this one being the Tax ID field:
// Custom format script for text field
if (!event.value) {
event.value = event.target.userName;
event.target.display = display.noPrint;
event.target.textColor = color.red;
} else {
event.target.display = display.visible;
event.target.textColor = color.black;
event.value = util.printx("99-9999999", event.value);
}
and the last line <event.value = util.printx("99-9999999", event.value);>
formats it correctly, like if it put in letter into the field then they aren't displayed and if I put in more than nine numbers then the extras aren't displayed.
But how do I make it so that you can't put in more than nine numbers or any letters?
How (if possible) would I get this to work? The if contained in the else statement:
// Custom format script for text field
if (!event.value) {
event.value = event.target.userName;
event.target.display = display.noPrint;
event.target.textColor = color.red;
} else {
event.target.display = display.visible;
event.target.textColor = color.black;
event.value = util.printx("99-9999999", event.value);
if (event.length !=10) {
event.value = "";
app.alert("Tax ID # does not have the required 9 numbers!", 0, 0)
}
}
HORRAY!!!! Actually I got the above code to work for the if statement contained in the else statement!!!!!!!!!
I have no idea how that works (again I know nothing about coding).
All I had to do was change it so it was:
// Custom format script for text field
if (!event.value) {
event.value = event.target.userName;
event.target.display = display.noPrint;
event.target.textColor = color.red;
} else {
event.target.display = display.visible;
event.target.textColor = color.black;
event.value = util.printx("99-9999999", event.value);
if (event.value.length !=10) {
event.value = "";
app.alert("Tax ID # does not have the required 9 numbers!", 0, 0)
}
}
North America
Europe, Middle East and Africa
Asia Pacific