| 1 |
\documentclass{article} |
| 2 |
\usepackage[designiv]{web} |
| 3 |
\usepackage[usehyforms]{grayhints} |
| 4 |
\usepackage{fancyvrb} |
| 5 |
|
| 6 |
|
| 7 |
\addtoWebHeight{1in} |
| 8 |
\def\cs#1{\texttt{\char`\\#1}} |
| 9 |
\let\app\textsf |
| 10 |
\let\pkg\textsf |
| 11 |
\let\uif\textsf |
| 12 |
\parindent0pt |
| 13 |
|
| 14 |
%\EnterCommitFailEvent{\jsT\jsT |
| 15 |
% event.target.strokeColor=color.blue;\jsR\jsT\jsT |
| 16 |
% event.value=(event.target.savevalue);} |
| 17 |
%\CommitSuccessEvent{event.target.strokeColor=color.red;} |
| 18 |
|
| 19 |
|
| 20 |
\begin{document} |
| 21 |
\begin{Form} |
| 22 |
\begin{center}\large\bfseries Gray Hints - Formats |
| 23 |
\end{center} |
| 24 |
The `gray hint' technique requires modifications to the Format, |
| 25 |
Keystroke, OnFocus, OnBlur, and Calculate events. Refer to \texttt{gh-fmts-eforms} for a more |
| 26 |
discussion of these fields.\medskip |
| 27 |
|
| 28 |
\renewcommand\LayoutTextField[2]{#2} |
| 29 |
\renewcommand\LayoutChoiceField[2]{#2} |
| 30 |
|
| 31 |
\TextField[% |
| 32 |
name={Datefield1}, |
| 33 |
height=11bp, |
| 34 |
width=1in, |
| 35 |
color={\matchGray}, |
| 36 |
keystroke={AFDate_KeystrokeEx("yyyy/mm/dd");\jsR |
| 37 |
\KeyToGray}, |
| 38 |
format={AFDate_FormatEx("yyyy/mm/dd");\jsR |
| 39 |
\FmtToGray{yyyy/mm/dd}}, |
| 40 |
onfocus={\FocusToBlack}, |
| 41 |
onblur={\BlurToBlack}, |
| 42 |
calculate={\CalcToGray} |
| 43 |
]{}\kern2bp\quad |
| 44 |
\TextField[% |
| 45 |
name={Datefield2}, |
| 46 |
height=11bp, |
| 47 |
width=1in, |
| 48 |
color={\matchGray}, |
| 49 |
keystroke={\DateKeyEx("yyyy/mm/dd");\jsR |
| 50 |
\KeyToGray}, |
| 51 |
format={\DateFmtEx("yyyy/mm/dd");\jsR |
| 52 |
\FmtToGray{yyyy/mm/dd}}, |
| 53 |
onfocus={\FocusToBlack}, |
| 54 |
onblur={\BlurToBlack}, |
| 55 |
calculate={\CalcToGray} |
| 56 |
]{}\medskip |
| 57 |
|
| 58 |
\textbf{Note:} In the discussion that follows, we assume you are using |
| 59 |
\app{Adobe Acrobat DC} (or prior), \app{Adobe Reader DC} (or prior) or |
| 60 |
\app{PDF-XChange Editor}. These PDF viewers support the JavaScript used |
| 61 |
by this package.\medskip |
| 62 |
|
| 63 |
The behavior of the field on the right requires some special code. |
| 64 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small,numbers=left,numbersep=9pt,commandchars={!~@}] |
| 65 |
\TextField[% |
| 66 |
name={Datefield2}, |
| 67 |
height=11bp,width=1in,charsize=9bp, |
| 68 |
color={\matchGray}, |
| 69 |
keystroke={\DateKeyEx("yyyy/mm/dd");\jsR |
| 70 |
\KeyToGray}, |
| 71 |
format={\DateFmtEx("yyyy/mm/dd");\jsR |
| 72 |
\FmtToGray{yyyy/mm/dd}}, |
| 73 |
onfocus={\FocusToBlack}, |
| 74 |
onblur={\BlurToBlack}, |
| 75 |
calculate={\CalcToGray} % <-!normalfont~ required for !app~PDF-XChange Editor@@ |
| 76 |
]{}\end{Verbatim} |
| 77 |
The code above is identical to that of the left-hand field with two |
| 78 |
exceptions, marked above by (5) and~(7). On these lines, the commands |
| 79 |
\cs{DateKeyEx} and \cs{DateFmtEx} are used (instead of the Adobe built-in |
| 80 |
functions directly). When these two are inserted, then we get the behavior of |
| 81 |
the field on the right on page 1.\medskip |
| 82 |
|
| 83 |
When the changes shown in lines~(5) and~(7) are made, you can customize the |
| 84 |
behavior of the field when the date is committed by pressing the \uif{Enter} |
| 85 |
key.\medskip |
| 86 |
|
| 87 |
\EnterCommitFailEvent{event.value=("weiter bearbeiten");} |
| 88 |
\TextField[% |
| 89 |
name={Datefield3}, |
| 90 |
height=11bp,width=1in,charsize=9bp, |
| 91 |
color={\matchGray}, |
| 92 |
keystroke={\DateKeyEx("yyyy/mm/dd");\jsR |
| 93 |
\KeyToGray}, |
| 94 |
format={\DateFmtEx("yyyy/mm/dd");\jsR |
| 95 |
\FmtToGray{yyyy/mm/dd}}, |
| 96 |
onfocus={\FocusToBlack}, |
| 97 |
onblur={\BlurToBlack}, |
| 98 |
calculate={\CalcToGray} |
| 99 |
]{}\medskip |
| 100 |
|
| 101 |
Here, we use \cs{EnterCommitFailEvent} and declare, |
| 102 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] |
| 103 |
\EnterCommitFailEvent{event.value=("weiter bearbeiten");} |
| 104 |
\end{Verbatim} |
| 105 |
which changes the text string that appears when \uif{Enter} is pressed for an invalid date.\medskip |
| 106 |
|
| 107 |
\EnterCommitFailEvent{% |
| 108 |
event.target.strokeColor=color.blue; |
| 109 |
event.value=(event.target.savevalue);} |
| 110 |
\CommitSuccessEvent{event.target.strokeColor=color.red;} |
| 111 |
We can get a different effect with |
| 112 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] |
| 113 |
\EnterCommitFailEvent{% |
| 114 |
event.target.strokeColor=color.blue; |
| 115 |
event.value=(event.target.savevalue);} |
| 116 |
\CommitSuccessEvent{event.target.strokeColor=color.black;} |
| 117 |
\end{Verbatim} |
| 118 |
The action declared by \cs{EnterCommitFailEvent} is to change the border |
| 119 |
color to blue, and secondly, to set the value of the field to the saved value |
| 120 |
(\texttt{event.target.savevalue}). The property \texttt{savevalue} is defined |
| 121 |
through the use of the special commands \cs{DateKeyEx} and \cs{DateFmtEx}. |
| 122 |
The action of \cs{CommitSuccessEvent} returns the fields border color to |
| 123 |
black.\medskip |
| 124 |
|
| 125 |
\TextField[% |
| 126 |
name={Datefield4}, |
| 127 |
height=11bp,width=1in,charsize=9bp, |
| 128 |
color={\matchGray}, |
| 129 |
keystroke={\DateKeyEx("yyyy/mm/dd");\jsR |
| 130 |
\KeyToGray}, |
| 131 |
format={\DateFmtEx("yyyy/mm/dd");\jsR |
| 132 |
\FmtToGray{yyyy/mm/dd}}, |
| 133 |
onfocus={\FocusToBlack}, |
| 134 |
onblur={\BlurToBlack}, |
| 135 |
calculate={\CalcToGray} |
| 136 |
]{}\medskip |
| 137 |
|
| 138 |
Now, when an invalid date is entered using the \uif{Enter} key, the border |
| 139 |
color of the field is changed to blue to indicate to the user that the date |
| 140 |
in invalid and needs to be modified. Tabbing or clicking outside the field, as |
| 141 |
usual, blurs the field; any invalid date is removed and the grayed hint |
| 142 |
appears.\medskip |
| 143 |
|
| 144 |
To return to the default declarations, expand \verb!\EnterCommitFailEvent{}! and |
| 145 |
\verb!\CommitSuccessEvent{}!. The underlying default actions are, |
| 146 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] |
| 147 |
\newcommand\FailStringDef{continue editing} |
| 148 |
\newcommand\EnterCommitFailDef{event.value=("\FailStringDef");} |
| 149 |
\end{Verbatim} |
| 150 |
A localization of language can be performed by redefining |
| 151 |
\cs{FailStringDef} |
| 152 |
\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] |
| 153 |
\renewcommand\FailStringDef{weiter bearbeiten} |
| 154 |
\end{Verbatim} |
| 155 |
|
| 156 |
The next example changes the border, the text color, and the error message.\medskip |
| 157 |
|
| 158 |
\EnterCommitFailEvent{\jsT |
| 159 |
event.target.strokeColor=color.blue;\jsR\jsT\jsT |
| 160 |
event.target.textColor=color.blue;\jsR\jsT\jsT |
| 161 |
event.value=("needs editing"); |
| 162 |
} |
| 163 |
\CommitSuccessEvent{\jsT\jsT |
| 164 |
event.target.strokeColor=color.red; |
| 165 |
} |
| 166 |
|
| 167 |
\noindent |
| 168 |
\TextField[% |
| 169 |
name={Datefield5}, |
| 170 |
height=11bp,width=1in,charsize=9bp, |
| 171 |
color={\matchGray}, |
| 172 |
keystroke={\DateKeyEx("yyyy/mm/dd");\jsR |
| 173 |
\KeyToGray}, |
| 174 |
format={\DateFmtEx("yyyy/mm/dd");\jsR |
| 175 |
\FmtToGray{yyyy/mm/dd}}, |
| 176 |
onfocus={\FocusToBlack}, |
| 177 |
onblur={\BlurToBlack}, |
| 178 |
calculate={\CalcToGray} |
| 179 |
]{}\qquad(enter `17' then press enter)\medskip |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
This same scheme should work for all the built-in Acrobat formats, let's look |
| 184 |
at the number format.\medskip |
| 185 |
|
| 186 |
\EnterCommitFailEvent{}\CommitSuccessEvent{} |
| 187 |
\TextField[% |
| 188 |
name=Integer, |
| 189 |
height=11bp,width=1in,charsize=9bp, |
| 190 |
color={\matchGray}, |
| 191 |
keystroke={\NumKey(0,1,0,0,"",true);\jsR\KeyToGray}, |
| 192 |
format={\NumFmt(0,1,0,0,"",true);\jsR |
| 193 |
\FmtToGray{Enter an Integer}}, |
| 194 |
onfocus={\FocusToBlack}, |
| 195 |
onblur={\BlurToBlack}, |
| 196 |
calculate={\CalcToGray} |
| 197 |
]{}\smallskip |
| 198 |
|
| 199 |
\textbf{Creating a Percent text field.}\medskip |
| 200 |
|
| 201 |
\TextField[% |
| 202 |
name=Percent, |
| 203 |
height=11bp,width=2in,charsize=9bp, |
| 204 |
color=\matchGray, |
| 205 |
keystroke={\PercentKey(2,1);\jsR |
| 206 |
\KeyToGray}, |
| 207 |
format={\PercentFmt(2,1);\jsR |
| 208 |
\FmtToGray{Enter a number}}, |
| 209 |
onfocus={\FocusToBlack}, |
| 210 |
onblur={\BlurToBlack}, |
| 211 |
calculate={\CalcToGray} |
| 212 |
]{} (don't enter the percent symbol \%)\medskip |
| 213 |
|
| 214 |
\textbf{Creating a Phone Number text field.}\medskip |
| 215 |
|
| 216 |
Enter a phone number: \TextField[% |
| 217 |
name=Phone, |
| 218 |
height=11bp,width=2in,charsize=9bp, |
| 219 |
color=\matchGray, |
| 220 |
keystroke={\SpecialKey(2);\jsR |
| 221 |
\KeyToGray}, |
| 222 |
format={\SpecialFmt(2);\jsR |
| 223 |
\FmtToGray{(123) 456-7890}}, |
| 224 |
onfocus={\FocusToBlack}, |
| 225 |
onblur={\BlurToBlack}, |
| 226 |
calculate={\CalcToGray} |
| 227 |
]{}\medskip |
| 228 |
|
| 229 |
The underlying JS function tries hard to make a phone number out of the input. The phone number can |
| 230 |
be entered in any recognized format; even something like 1234567890 is recognized and formatted.\medbreak |
| 231 |
|
| 232 |
\textbf{Creating a Custom time format text field.}\medskip |
| 233 |
|
| 234 |
\def\parentt{(tt)} % necessary to insert within arg of \TimeFmtEx |
| 235 |
\TextField[% |
| 236 |
name=Time, |
| 237 |
height=11bp,width=2in,charsize=9bp, |
| 238 |
color=\matchGray, |
| 239 |
keystroke={\TimeKey(0);\jsR |
| 240 |
\KeyToGray}, |
| 241 |
format={\TimeFmtEx("h:MM \parentt");\jsR |
| 242 |
\FmtToGray{Enter a time}}, |
| 243 |
onfocus={\FocusToBlack}, |
| 244 |
onblur={\BlurToBlack}, |
| 245 |
calculate={\CalcToGray} |
| 246 |
]{}\quad\PushButton[% |
| 247 |
height=11bp, |
| 248 |
name=pbtime, |
| 249 |
onclick={var cTime=util.printd("h:MM",new Date());\jsR |
| 250 |
var f=this.getField("Time");\jsR |
| 251 |
f.value=cTime;}]{UCT}\medskip |
| 252 |
|
| 253 |
Detailed information on formatting with the built-in functions of \app{Acrobat} may be found at |
| 254 |
the \href{http://blog.acrotex.net}{Acro\negthinspace\TeX\space Blog}; in particular, see the article \url{http://www.acrotex.net/blog/?p=218}. |
| 255 |
|
| 256 |
\end{Form} |
| 257 |
\end{document} |