| 1 |
\documentclass{article} |
| 2 |
\usepackage[designiv]{web} |
| 3 |
\usepackage{grayhints}\previewOff |
| 4 |
\usepackage{fancyvrb} |
| 5 |
|
| 6 |
\addtoWebHeight{1in} |
| 7 |
\def\cs#1{\texttt{\char`\\#1}} |
| 8 |
\let\app\textsf |
| 9 |
\let\pkg\textsf |
| 10 |
\let\uif\textsf |
| 11 |
\parindent0pt |
| 12 |
|
| 13 |
%\EnterCommitFailEvent{\jsT\jsT |
| 14 |
% event.target.strokeColor=color.red;\jsR\jsT\jsT |
| 15 |
% event.value=(event.target.savevalue);} |
| 16 |
%\CommitSuccessEvent{event.target.strokeColor=color.black;} |
| 17 |
|
| 18 |
\begin{document} |
| 19 |
|
| 20 |
\begin{center} |
| 21 |
\large\bfseries Gray Hints - Formats |
| 22 |
\end{center} |
| 23 |
The `gray hints' technique works well with fields that require special |
| 24 |
formatting such as the ones provided by built-in formats of \app{Adobe |
| 25 |
Acrobat}, these formats are Number, Percentage, Date, Time, Special, and |
| 26 |
Custom. How `gray hints' functions when one of these special formats is |
| 27 |
used may be acceptable, but if not, we offer an alternative. First we compare |
| 28 |
two date fields. The one on the left is the default, the one on the right is |
| 29 |
`enhanced.'\medskip |
| 30 |
|
| 31 |
\textField[\textColor{\matchGray} |
| 32 |
\TU{Enter a date of your choosing} |
| 33 |
\AA{% |
| 34 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 35 |
% Using the Adobe Built-in functions directly |
| 36 |
\AAKeystroke{AFDate_KeystrokeEx("yyyy/mm/dd");\r |
| 37 |
\KeyToGray} |
| 38 |
\AAFormat{AFDate_FormatEx("yyyy/mm/dd");\r |
| 39 |
\FmtToGray{yyyy/mm/dd}} |
| 40 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 41 |
\AACalculate{\CalcToGray} |
| 42 |
}]{Datefield1}{1in}{11bp}\kern2bp\quad |
| 43 |
\textField[\textColor{\matchGray} |
| 44 |
\TU{Enter a date of your choosing} |
| 45 |
\AA{% |
| 46 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 47 |
% using a customized version of Adobe built-in functions, with LaTeX access |
| 48 |
\AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r |
| 49 |
\KeyToGray} |
| 50 |
\AAFormat{\DateFmtEx("yyyy/mm/dd");\r |
| 51 |
\FmtToGray{yyyy/mm/dd}} |
| 52 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 53 |
\AACalculate{\CalcToGray} |
| 54 |
}]{Datefield2}{1in}{11bp}\hfill\begin{minipage}{\linewidth-2in-6bp-1em-6pt}\footnotesize |
| 55 |
The underlying JS function tries hard to make a date from the input. You can enter a date |
| 56 |
in most any format as long it is in the order of the date elements YEAR MONTH DAY (yyyy/mm/dd), as determined by the |
| 57 |
formatting template. (For example, try 2018 Jan 10). |
| 58 |
\end{minipage}\medskip |
| 59 |
|
| 60 |
|
| 61 |
\textbf{Note:} In the discussion that follows, we assume you are using |
| 62 |
\app{Adobe Acrobat DC} (or prior), \app{Adobe Reader DC} (or prior) or |
| 63 |
\app{PDF-XChange Editor}. These PDF viewers support the JavaScript used |
| 64 |
by this package.\medskip |
| 65 |
|
| 66 |
\textbf{Discussion:} Enter an \emph{invalid date} into each field (such as |
| 67 |
the number 17), and \emph{commit} that number to the field. There are several |
| 68 |
ways of committing form data: (1) press the \uif{Enter} key; (2) tab out of the |
| 69 |
field; (3) click or tap outside the field; and (4) move to another |
| 70 |
page.\footnote{Apparently, \app{PDF-XChange Editor} does not commit field |
| 71 |
data when the page is turned, unlike the Adobe PDF viewer.} The behavior of |
| 72 |
the field is the same for cases (2)--(4); in those cases, the field loses |
| 73 |
focus (or is blurred). In the first case, the data is committed, but |
| 74 |
\emph{not blurred}. This latter case is a bit of a problem because the blur |
| 75 |
event has JavaScript that sets the field text color, as appropriate.\medskip |
| 76 |
|
| 77 |
In the above two fields, enter the number 17 (or any invalid date) and commit |
| 78 |
the data using method (2) or (3); now repeat the exercise for the two fields, |
| 79 |
but commit using method (1). Do you notice a difference?\medskip |
| 80 |
|
| 81 |
\textbf{Discussion of (2) and (3):} This is the usual case; after the alert |
| 82 |
dialog box is dismissed, the fields are grayed out again. That's the effect |
| 83 |
desired by this package.\medskip |
| 84 |
|
| 85 |
\textbf{Discussion of (1):} When the data is committed by pressing the |
| 86 |
\uif{Enter} key and the alert box is dismissed, for the field on the left |
| 87 |
`yyyy/mm/dd' appears in black, whereas, for the field on the right, the |
| 88 |
string `continue editing' appears in black. In each case, you can click |
| 89 |
within the field and continue editing the date. Use methods (2) or (3) to |
| 90 |
commit your final response. Of the two fields, the behavior of the field on |
| 91 |
the right is the preferred one.\medskip |
| 92 |
|
| 93 |
The behavior of the field on the right requires some special code. |
| 94 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small,numbers=left,numbersep=9pt,commandchars={!~@}] |
| 95 |
\textField[\textColor{\matchGray} |
| 96 |
\TU{Enter a date of your choosing} |
| 97 |
\AA{% |
| 98 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 99 |
\AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r |
| 100 |
\KeyToGray} |
| 101 |
\AAFormat{\DateFmtEx("yyyy/mm/dd");\r |
| 102 |
\FmtToGray{yyyy/mm/dd}} |
| 103 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 104 |
\AACalculate{\CalcToGray} % <-!normalfont~ required for !app~PDF-XChange Editor@@ |
| 105 |
}]{Datefield2}{1in}{11bp} |
| 106 |
\end{Verbatim} |
| 107 |
The code above is identical to that of the left-hand field with two |
| 108 |
exceptions, marked above by (5) and~(7). On these lines, the commands |
| 109 |
\cs{DateKeyEx} and \cs{DateFmtEx} are used (instead of the Adobe built-in |
| 110 |
functions directly). When these two are inserted, then we get the behavior of |
| 111 |
the field on the right on page 1.\medskip |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
When the changes shown in lines~(5) and~(7) are made, you can customize the |
| 116 |
behavior of the field when the date is committed by pressing the \uif{Enter} |
| 117 |
key.\medskip |
| 118 |
|
| 119 |
\EnterCommitFailEvent{event.value=("weiter bearbeiten");} |
| 120 |
\textField[\textColor{\matchGray} |
| 121 |
\TU{Enter a date of your choosing} |
| 122 |
\AA{% |
| 123 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 124 |
\AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r |
| 125 |
\KeyToGray} |
| 126 |
\AAFormat{\DateFmtEx("yyyy/mm/dd");\r |
| 127 |
\FmtToGray{yyyy/mm/dd}} |
| 128 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 129 |
\AACalculate{\CalcToGray} |
| 130 |
}]{Datefield3}{1in}{11bp}\medskip |
| 131 |
|
| 132 |
Here, we use \cs{EnterCommitFailEvent} and declare, |
| 133 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] |
| 134 |
\EnterCommitFailEvent{event.value=("weiter bearbeiten");} |
| 135 |
\end{Verbatim} |
| 136 |
which changes the text string that appears when \uif{Enter} is pressed for an invalid date.\medskip |
| 137 |
|
| 138 |
\EnterCommitFailEvent{% |
| 139 |
event.target.strokeColor=color.red; |
| 140 |
event.value=(event.target.savevalue);} |
| 141 |
\CommitSuccessEvent{event.target.strokeColor=color.black;} |
| 142 |
We can get a different effect with |
| 143 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] |
| 144 |
\EnterCommitFailEvent{% |
| 145 |
event.target.strokeColor=color.red; |
| 146 |
event.value=(event.target.savevalue);} |
| 147 |
\CommitSuccessEvent{event.target.strokeColor=color.black;} |
| 148 |
\end{Verbatim} |
| 149 |
The action declared by \cs{EnterCommitFailEvent} is to change the border |
| 150 |
color to red, and secondly, to set the value of the field to the saved value |
| 151 |
(\texttt{event.target.savevalue}). The property \texttt{savevalue} is defined |
| 152 |
through the use of the special commands \cs{DateKeyEx} and \cs{DateFmtEx}. |
| 153 |
The action of \cs{CommitSuccessEvent} returns the fields border color to |
| 154 |
black.\medskip |
| 155 |
|
| 156 |
\textField[\textColor{\matchGray} |
| 157 |
\TU{Enter a date of your choosing} |
| 158 |
\AA{% |
| 159 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 160 |
\AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r |
| 161 |
\KeyToGray} |
| 162 |
\AAFormat{\DateFmtEx("yyyy/mm/dd");\r |
| 163 |
\FmtToGray{yyyy/mm/dd}} |
| 164 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 165 |
\AACalculate{\CalcToGray} |
| 166 |
}]{Datefield4}{1in}{11bp}\medskip |
| 167 |
|
| 168 |
Now, when an invalid date is entered using the \uif{Enter} key, the border |
| 169 |
color of the field is changed to red to indicate to the user that the date |
| 170 |
in invalid and needs to be modified. Tabbing or clicking outside the field, as |
| 171 |
usual, blurs the field; any invalid date is removed and the grayed hint |
| 172 |
appears.\medskip |
| 173 |
|
| 174 |
To return to the default declarations, expand \verb!\EnterCommitFailEvent{}! and |
| 175 |
\verb!\CommitSuccessEvent{}!. The underlying default actions are, |
| 176 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] |
| 177 |
\newcommand\FailStringDef{continue editing} |
| 178 |
\newcommand\EnterCommitFailDef{event.value=("\FailStringDef");} |
| 179 |
\end{Verbatim} |
| 180 |
A localization of language can be performed by redefining |
| 181 |
\cs{FailStringDef} |
| 182 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] |
| 183 |
\renewcommand\FailStringDef{weiter bearbeiten} |
| 184 |
\end{Verbatim} |
| 185 |
|
| 186 |
The next example changes the border, the text color, and the error message.\medskip |
| 187 |
|
| 188 |
\EnterCommitFailEvent{\t |
| 189 |
event.target.strokeColor=color.red;\r\t\t |
| 190 |
event.target.textColor=color.red;\r\t\t |
| 191 |
event.value=("needs editing"); |
| 192 |
} |
| 193 |
\CommitSuccessEvent{\t\t |
| 194 |
event.target.strokeColor=color.black; |
| 195 |
} |
| 196 |
|
| 197 |
\noindent |
| 198 |
\textField[\textColor{\matchGray} |
| 199 |
\TU{Enter a date of your choosing}\AA{% |
| 200 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 201 |
% using a customized version of Adobe built-in functions, with LaTeX access |
| 202 |
\AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r |
| 203 |
\KeyToGray} |
| 204 |
\AAFormat{\DateFmtEx("yyyy/mm/dd");\r |
| 205 |
\FmtToGray{yyyy/mm/dd}} |
| 206 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 207 |
\AACalculate{\CalcToGray} |
| 208 |
}]{Datefield5}{1in}{11bp}\qquad(enter `17' then press enter)\medskip |
| 209 |
|
| 210 |
This same scheme should work for all the built-in Acrobat formats, let's look |
| 211 |
at the number format.\medskip |
| 212 |
|
| 213 |
\EnterCommitFailEvent{}\CommitSuccessEvent{} |
| 214 |
\textField[\TU{Enter an integer} |
| 215 |
\textColor{\matchGray}\AA{% |
| 216 |
\AAKeystroke{\NumKey(0,1,0,0,"",true);\r\KeyToGray} |
| 217 |
\AAFormat{\NumFmt(0,1,0,0,"",true);\r |
| 218 |
\FmtToGray{Enter an Integer}} |
| 219 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 220 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 221 |
\AACalculate{\CalcToGray} |
| 222 |
}]{Integer}{1in}{11bp}\medskip |
| 223 |
|
| 224 |
\textbf{Creating a Percent text field.}\medskip |
| 225 |
|
| 226 |
\textField[\textColor{\matchGray}\AA{% |
| 227 |
\AAKeystroke{\PercentKey(2,1);\r |
| 228 |
\KeyToGray} |
| 229 |
\AAFormat{\PercentFmt(2,1);\r |
| 230 |
\FmtToGray{Enter a number}} |
| 231 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 232 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 233 |
\AACalculate{\CalcToGray} |
| 234 |
}]{Percent}{2in}{11bp} (don't enter the percent symbol \%)\medskip |
| 235 |
|
| 236 |
\textbf{Creating a Phone Number text field.}\medskip |
| 237 |
|
| 238 |
Enter a phone number: \textField[\textColor{\matchGray}\AA{% |
| 239 |
\AAKeystroke{\SpecialKey(2);\r |
| 240 |
\KeyToGray} |
| 241 |
\AAFormat{\SpecialFmt(2);\r |
| 242 |
\FmtToGray{(123) 456-7890}} |
| 243 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 244 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 245 |
\AACalculate{\CalcToGray} |
| 246 |
}]{Phone}{2in}{11bp}\medskip |
| 247 |
|
| 248 |
The underlying JS function tries hard to make a phone number out of the input. The phone number can |
| 249 |
be entered in any recognized format; even something like 1234567890 is formatted.\medbreak |
| 250 |
|
| 251 |
\textbf{Creating a Custom time format text field.}\medskip |
| 252 |
|
| 253 |
\def\parentt{(tt)} % necessary to insert within arg of \TimeFmtEx |
| 254 |
\textField[\textColor{\matchGray}\AA{% |
| 255 |
\AAKeystroke{\TimeKey(0);\r |
| 256 |
\KeyToGray} |
| 257 |
\AAFormat{\TimeFmtEx("h:MM \parentt");\r |
| 258 |
\FmtToGray{Enter a time}} |
| 259 |
\AAOnFocus{\JS{\FocusToBlack}} |
| 260 |
\AAOnBlur{\JS{\BlurToBlack}} |
| 261 |
\AACalculate{\CalcToGray} |
| 262 |
}]{Time}{2in}{11bp}\kern1bp\pushButton[\TU{Push to Use Current Time} |
| 263 |
\CA{UCT}\A{\JS{% |
| 264 |
var cTime=util.printd("h:MM",new Date());\r |
| 265 |
var f=this.getField("Time");\r |
| 266 |
f.value=cTime; |
| 267 |
}}]{pbTime}{}{11bp}\medskip |
| 268 |
|
| 269 |
Detailed information on formatting with the built-in functions of \app{Acrobat} may be found at |
| 270 |
the \href{http://blog.acrotex.net}{Acro\negthinspace\TeX\space Blog}; in particular, see the article |
| 271 |
\url{http://www.acrotex.net/blog/?p=218}. |
| 272 |
|
| 273 |
\end{document} |