📄 aform.js
字号:
nValue = nValue1 + nValue2;
break;
case "PRD":
nValue = nValue1 * nValue2;
break;
case "MIN":
nValue = Math.min(nValue1,nValue2);
break;
case "MAX":
nValue = Math.max(nValue1, nValue2);
break;
}
return nValue;
}
function AFSimple_Calculate(cFunction, cFields)
{ /* Calculates the sum, average, product, etc. of the listed field values. */
var nFields = 0;
var nValue = AFSimpleInit(cFunction);
/* Field name separator is one or more spaces followed by a comma,
** followed by one or more spaces.
** or an array of field names */
var aFields = AFMakeArrayFromList(cFields);
for (var i = 0; i < aFields.length; i++) {
/* Found a field, process it's value. */
var f = this.getField(aFields[i]);
var a = f.getArray();
for (var j = 0; j < a.length; j++) {
var nTemp = AFMakeNumber(a[j].value);
if (i == 0 && j == 0 && (cFunction == "MIN" || cFunction == "MAX"))
nValue = nTemp;
nValue = AFSimple(cFunction, nValue, nTemp);
nFields++;
}
}
if (cFunction == "AVG" && nFields > 0)
nValue /= nFields;
event.value = nValue;
}
function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
{ /* This function validates the current keystroke event to make sure the
key pressed is reasonable for a numeric field. */
var value = AFMergeChange(event);
var commit, noCommit;
if(!value) return;
if(sepStyle > 1)
{
commit = AFNumberCommaSepCommitRegExp;
noCommit = AFNumberCommaSepEntryRegExp;
}
else
{
commit = AFNumberDotSepCommitRegExp;
noCommit = AFNumberDotSepEntryRegExp;
}
if(!AFExactMatch(event.willCommit ? commit : noCommit, value))
{
if (event.willCommit) {
var cAlert = IDS_INVALID_VALUE;
if (event.target != null)
cAlert += " [ " + event.target.name + " ]";
app.alert(cAlert);
}
else
app.beep(0);
event.rc = false;
}
}
function AFPercent_Keystroke(nDec, sepStyle)
{
AFNumber_Keystroke(nDec, sepStyle, 0, 0, "", true);
}
function AFSpecial_Keystroke(psf)
{ /* This function validates the current keystroke event to make sure the
key pressed is reasonable for a "special" field. */
/* The special formats, indicated by psf, are:
psf format
--- ------
0 zip code
1 zip + 4
2 phone
3 SSN
*/
var value = AFMergeChange(event);
var commit, noCommit;
if(!value) return;
switch (psf)
{
case 0:
commit = AFZipCommitRegExp;
noCommit = AFZipEntryRegExp;
break;
case 1:
commit = AFZip4CommitRegExp;
noCommit = AFZip4EntryRegExp;
break;
case 2:
commit = AFPhoneCommitRegExp;
noCommit = AFPhoneEntryRegExp;
break;
case 3:
commit = AFSSNCommitRegExp;
noCommit = AFSSNEntryRegExp;
break;
}
if(!AFExactMatch(event.willCommit ? commit : noCommit, value))
{
if (event.willCommit) {
var cAlert = IDS_INVALID_VALUE;
if (event.target != null)
cAlert += " [ " + event.target.name + " ]";
app.alert(cAlert);
}
else
app.beep(0);
event.rc = false;
}
}
function AFDate_KeystrokeEx(cFormat)
{ /* This function validates the current keystroke event to make sure the
** key pressed is reasonable for a date field. */
if(event.willCommit && !AFParseDateEx(AFMergeChange(event), cFormat)) {
/* Dates are only validated on commit */
if (event.willCommit) {
var cAlert = IDS_INVALID_DATE;
if (event.target != null)
cAlert += " [ " + event.target.name + " ]";
app.alert(cAlert);
if (event.target != null)
event.target.setFocus();
}
else
app.beep(0);
event.rc = false;
}
}
function AFDate_Keystroke(pdf)
{ /* OBSOLETE: Use AFDate_KeystrokeEx. */
var cOldFormats = new Array(
"m/d", "m/d/yy", "mm/dd/yy", "mm/yy", "d-mmm", "d-mmm-yy", "dd-mmm-yy",
"yy-mm-dd", "mmm-yy", "mmmm-yy", "mmm d, yyyy", "mmmm d, yyyy",
"m/d/yy h:MM tt", "m/d/yy HH:MM" );
AFDate_KeystrokeEx(cOldFormats[pdf]);
}
function AFTime_Keystroke(ptf)
{ /* This function validates the current keystroke event to make sure the
key pressed is reasonable for a time field. */
if(event.willCommit && !AFParseTime(event.value, null))
/* times are only validated on commit */
{
if (event.willCommit) {
var cAlert = IDS_INVALID_VALUE;
if (event.target != null)
cAlert += " [ " + event.target.name + " ]";
app.alert(cAlert);
}
else
app.beep(0);
event.rc = false;
}
}
function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
{ /* This function formats a numeric value according to the parameters. */
var value = AFMakeNumber(event.value);
var sign = (value < 0 ? -1 : 1);
var f = event.target;
if(value == null)
{
event.value = "";
return;
}
if ((negStyle == 2 /* ParensBlack */ || negStyle == 3 /* ParensRed */) && value < 0)
var formatStr = "(";
else
var formatStr = "";
if (bCurrencyPrepend)
formatStr = formatStr + strCurrency;
formatStr = formatStr + "%," + sepStyle + "." + nDec + "f";
if (! bCurrencyPrepend)
formatStr = formatStr + strCurrency;
if ((negStyle == 2 /* ParensBlack */ || negStyle == 3 /* ParensRed */) && value < 0)
formatStr = formatStr + ")";
if (negStyle != 0 /* MinusBlack */ || bCurrencyPrepend)
value = Math.abs(value);
if (negStyle == 1 /* Red */ || negStyle == 3 /* ParensRed */) {
if (sign > 0 )
f.textColor = color.black;
else
f.textColor = color.red;
}
var tmp = util.printf(formatStr, value);
if (sign < 0 && bCurrencyPrepend && negStyle == 0)
tmp = '-' + tmp; /* prepend the -ve sign */
event.value = tmp;
}
function AFPercent_Format(nDec, sepStyle)
{ /* This function formats a percentage value according to the parameters. */
var value = AFMakeNumber(event.value) * 100;
var formatStr = "%," + sepStyle + "." + nDec + "f";
if(value == null)
{
event.value = "";
return;
}
value = util.printf(formatStr, value);
event.value = value + "%";
}
function AFSpecial_Format(psf)
{ /* This function formats a "special" value according to the "PropsSpecialFormat" parameter psf. */
/* The special formats, indicated by psf, are: 0 = zip code, 1 = zip + 4, 2 = phone, 3 = SSN. */
var value = event.value;
if(!value) return;
switch (psf) {
case 0:
var formatStr = "99999";
break;
case 1:
var formatStr = "99999-9999";
break;
case 2: /* must distinguish between 2 styles: with and without area code */
var NumbersStr = util.printx("9999999999", value); /* try to suck out 10 numeric chars */
if (NumbersStr.length >= 10 )
var formatStr = "(999) 999-9999";
else
var formatStr = "999-9999";
break;
case 3:
var formatStr = "999-99-9999";
break;
}
event.value = util.printx(formatStr, value);
}
function AFParseDateYCount(cFormat)
{
/* Determine the order of the date. */
var yCount = 0;
for (var i = 0; i < cFormat.length; i++) {
switch (cFormat.charAt(i)) {
case "\\": /* Escape character. */
i++;
break;
case "y":
yCount += 1;
break;
}
}
return yCount;
}
function AFParseDateOrder(cFormat)
{
/* Determine the order of the date. */
var cOrder = "";
for (var i = 0; i < cFormat.length; i++) {
switch (cFormat.charAt(i)) {
case "\\": /* Escape character. */
i++;
break;
case "m":
if (cOrder.indexOf("m") == -1)
cOrder += "m";
break;
case "d":
if (cOrder.indexOf("d") == -1)
cOrder += "d";
break;
case "y":
if (cOrder.indexOf("y") == -1)
cOrder += "y";
break;
}
}
/* Make sure we have a full complement of 3 chars. */
if (cOrder.indexOf("m") == -1)
cOrder += "m";
if (cOrder.indexOf("d") == -1)
cOrder += "d";
if (cOrder.indexOf("y") == -1)
cOrder += "y";
return cOrder;
}
function AFDate_FormatEx(cFormat)
{ /* cFormat is a format string with which the date is to be formatted. */
if (!event.value)
return; /* Blank fields remain blank */
var date = AFParseDateEx(event.value, cFormat);
if (!date) {
event.value = "";
return;
}
event.value = util.printd(cFormat, date);
}
function AFDate_Format(pdf)
{ /* OBSOLETE: Use AFDate_FormatEx. */
var cOldFormats = new Array(
"m/d", "m/d/yy", "mm/dd/yy", "mm/yy", "d-mmm", "d-mmm-yy", "dd-mmm-yy",
"yy-mm-dd", "mmm-yy", "mmmm-yy", "mmm d, yyyy", "mmmm d, yyyy",
"m/d/yy h:MM tt", "m/d/yy HH:MM" );
AFDate_FormatEx(cOldFormats[pdf]);
}
function AFTime_Format(ptf)
{ /* This function formats a time value according to the "PropsTimeFormat" parameter ptf.
** The time formats, indicated by ptf, are:
** ptf format
** --- ------
** 0 PTF_24HR_MM [ 14:30 ]
** 1 PTF_12HR_MM [ 2:30 PM ]
** 2 PTF_24HR_MM_SS [ 14:30:15 ]
** 3 PTF_12HR_MM_SS [ 2:30:15 PM ] */
if(!event.value) return; /* Blank fields remain blank */
var date = new AFParseTime(event.value, null);
if(!date) {
event.value = "";
return;
}
var cFormats = new Array(
"HH:MM", "h:MM tt", "HH:MM:ss", "h:MM:ss tt" );
event.value = util.printd(cFormats[ptf], date);
}
function AFSignatureLock(doc, cOperation, cFields, bLock)
{ // Locks or unlocks a set of fields according to the specified operation.
/* Field name separator is one or more spaces followed by a comma,
** followed by one or more spaces.
** or an array of field names */
var aFields = AFMakeArrayFromList(cFields);
/* Three cases: ALL, EXCEPT, THESE for the field name list. */
if (cOperation != "THESE") {
for (var i = 0; i < doc.numFields; i++) {
var f = doc.getField(doc.getNthFieldName(i));
f.readonly = bLock;
}
}
if (cOperation == "EXCEPT")
/* EXCEPT = ALL(lock) then THESE(unlock) */
bLock = !bLock;
if (cOperation == "THESE" || (cOperation == "EXCEPT" && !bLock)) {
for (var i = 0; i < aFields.length; i++) {
var f = doc.getField(aFields[i]);
var a = f.getArray();
for (var j = 0; j < a.length; j++) {
a[j].readonly = bLock;
}
}
}
}
function AFSignature_Format(cOperation, cFields)
{ /* This function is invoked at format time but really is used to lock fields
** in the document. We unlock all the specified fields if the value is
** null (which means the signature hasn't been applied). */
var bLock = (event.value != "");
AFSignatureLock(this, cOperation, cFields, bLock);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -