diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/grayhints/examples |
Initial commit
Diffstat (limited to 'macros/latex/contrib/grayhints/examples')
-rw-r--r-- | macros/latex/contrib/grayhints/examples/gh-eforms.pdf | bin | 0 -> 104160 bytes | |||
-rw-r--r-- | macros/latex/contrib/grayhints/examples/gh-eforms.tex | 117 | ||||
-rw-r--r-- | macros/latex/contrib/grayhints/examples/gh-fmts-eforms.tex | 273 | ||||
-rw-r--r-- | macros/latex/contrib/grayhints/examples/gh-fmts-hyperref.tex | 257 | ||||
-rw-r--r-- | macros/latex/contrib/grayhints/examples/gh-hyperref.tex | 151 |
5 files changed, 798 insertions, 0 deletions
diff --git a/macros/latex/contrib/grayhints/examples/gh-eforms.pdf b/macros/latex/contrib/grayhints/examples/gh-eforms.pdf Binary files differnew file mode 100644 index 0000000000..f726a7b9f1 --- /dev/null +++ b/macros/latex/contrib/grayhints/examples/gh-eforms.pdf diff --git a/macros/latex/contrib/grayhints/examples/gh-eforms.tex b/macros/latex/contrib/grayhints/examples/gh-eforms.tex new file mode 100644 index 0000000000..4f9e9f8f5b --- /dev/null +++ b/macros/latex/contrib/grayhints/examples/gh-eforms.tex @@ -0,0 +1,117 @@ +\documentclass{article} +\usepackage[designiv]{web} +\usepackage{grayhints}\previewOff + +\addtoWebHeight{1in} +\def\cs#1{\texttt{\char`\\#1}} +\parindent0pt + +%\EnterCommitFailEvent{\jsT\jsT +% event.target.strokeColor=color.red;\jsR\jsT\jsT +% event.value=(event.target.savevalue);} +%\CommitSuccessEvent{event.target.strokeColor=color.black;} + +\begin{document} + +\begin{center} + \large\bfseries Gray Hints +\end{center} +The `gray hint' technique requires modifications to the Format, +Keystroke, OnFocus, OnBlur, and Calculate events.\medskip + +\textField[\textColor{\matchGray} + \TU{Enter your first name} + \AA{\AAFormat{\FmtToGray{First Name}} + \AAKeystroke{\KeyToGray} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Name.First}{2in}{11bp}\cgBdry[1em] +\textField[\textColor{\matchGray} + \TU{Enter your last name} + \AA{\AAFormat{\FmtToGray{Last Name}} + \AAKeystroke{\KeyToGray} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Name.Last}{2in}{11bp}\cgBdry[1em]\vcgBdry[3bp] +\textField[\textColor{\matchGray} + \TU{Enter a date of your choosing} + \AA{% + \AAOnFocus{\JS{\FocusToBlack}} + \AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r + \KeyToGray} + \AAFormat{\DateFmtEx("yyyy/mm/dd");\r + \FmtToGray{yyyy/mm/dd}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Datefield}{1in}{11bp}\kern2bp\enspace$\Leftarrow$\enspace +\parbox{\linewidth-1in-2bp-\widthof{\enspace$\Leftarrow$\enspace}} +{\small Refer to \texttt{gh-fmts-eforms.tex} for additional discussion of +fields requiring special formatting.}\medskip + +The next three fields perform calculations, the last one is the sum of the +first two. These are fields formatted as numbers. To prevent `Total' field +from displaying a zero (0) when the dependent fields are empty (and to +display its gray hint instead), a document JavaScript function was developed, +named \texttt{AllowCalc(cArray)}. This function returns \texttt{true} if any +of the fields listed in \texttt{cArray} has a value and returns +\texttt{false}, otherwise.\vcgBdry[6bp] + +\textField[\TU{Enter an integer} + \textColor{\matchGray}\AA{% + \AAKeystroke{\NumKey(0,1,0,0,"",true);\r\KeyToGray} + \AAFormat{\NumFmt(0,1,0,0,"",true);\r\FmtToGray{First Integer}} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Integer.First}{1in}{11bp}\vcgBdry[3bp] +\textField[\TU{Enter an integer} + \textColor{\matchGray}\AA{% + \AAKeystroke{\NumKey(0,1,0,0,"",true);\r\KeyToGray} + \AAFormat{\NumFmt(0,1,0,0,"",true);\r\FmtToGray{Second Integer}} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Integer.Second}{1in}{11bp}\vcgBdry[3bp] +\textField[\TU{The total for first and second integers} + \textColor{\matchGray}\AA{% + \AAKeystroke{\NumKey(0,1,0,0,"",true);\r\KeyToGray} + \AAFormat{\NumFmt(0,1,0,0,"",true);\r\FmtToGray{Total}} + \AACalculate{var cArray=new Array("Integer");\r + if (AllowCalc(cArray))\SimpleCalc("SUM", cArray );\r\CalcToGray} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} +}]{TotalNumbers}{1in}{11bp}\medskip + +The gray hint technique can apply to editable combo boxes as well.\vcgBdry[3bp] +\comboBox[\textColor{\matchGray} + \TU{Enter or choose your favorite food}\Ff{\FfEdit} + \AA{\AAFormat{\FmtToGray{Enter your favorite food}} + \AAKeystroke{\KeyToGray} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{combo}{1.65in}{11bp}{(Meat)(Potatoes)(Rice)(Onions)(Pickles)}\cgBdry[1em] +\pushButton[\CA{Reset} + \TU{Press to clear to clear all fields.} + \A{\JS{this.resetForm();}}]{reset}{}{11bp}\medskip + +The color scheme of the gray hints is changed using +\cs{normalGrayColors}. The initial value of \cs{textColor}, which sets the +color of the text, must match, for appearance sake, the choice for the gray +color; for this reason, the \cs{matchGray} command was developed.\vcgBdry[6bp] + +%\normalGrayColors{blue}{magenta} +\normalGrayColors{color.blue}{color.magenta} + +\textField[\textColor{\matchGray} + \TU{Enter your favorite pet's name} + \AA{\AAFormat{\FmtToGray{Pet's name}} + \AAKeystroke{\KeyToGray} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Pet}{1in}{11bp} + +\end{document} diff --git a/macros/latex/contrib/grayhints/examples/gh-fmts-eforms.tex b/macros/latex/contrib/grayhints/examples/gh-fmts-eforms.tex new file mode 100644 index 0000000000..cf6186da19 --- /dev/null +++ b/macros/latex/contrib/grayhints/examples/gh-fmts-eforms.tex @@ -0,0 +1,273 @@ +\documentclass{article} +\usepackage[designiv]{web} +\usepackage{grayhints}\previewOff +\usepackage{fancyvrb} + +\addtoWebHeight{1in} +\def\cs#1{\texttt{\char`\\#1}} +\let\app\textsf +\let\pkg\textsf +\let\uif\textsf +\parindent0pt + +%\EnterCommitFailEvent{\jsT\jsT +% event.target.strokeColor=color.red;\jsR\jsT\jsT +% event.value=(event.target.savevalue);} +%\CommitSuccessEvent{event.target.strokeColor=color.black;} + +\begin{document} + +\begin{center} + \large\bfseries Gray Hints - Formats +\end{center} +The `gray hints' technique works well with fields that require special +formatting such as the ones provided by built-in formats of \app{Adobe +Acrobat}, these formats are Number, Percentage, Date, Time, Special, and +Custom. How `gray hints' functions when one of these special formats is +used may be acceptable, but if not, we offer an alternative. First we compare +two date fields. The one on the left is the default, the one on the right is +`enhanced.'\medskip + +\textField[\textColor{\matchGray} + \TU{Enter a date of your choosing} + \AA{% + \AAOnFocus{\JS{\FocusToBlack}} +% Using the Adobe Built-in functions directly + \AAKeystroke{AFDate_KeystrokeEx("yyyy/mm/dd");\r + \KeyToGray} + \AAFormat{AFDate_FormatEx("yyyy/mm/dd");\r + \FmtToGray{yyyy/mm/dd}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Datefield1}{1in}{11bp}\kern2bp\quad +\textField[\textColor{\matchGray} + \TU{Enter a date of your choosing} + \AA{% + \AAOnFocus{\JS{\FocusToBlack}} +% using a customized version of Adobe built-in functions, with LaTeX access + \AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r + \KeyToGray} + \AAFormat{\DateFmtEx("yyyy/mm/dd");\r + \FmtToGray{yyyy/mm/dd}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Datefield2}{1in}{11bp}\hfill\begin{minipage}{\linewidth-2in-6bp-1em-6pt}\footnotesize +The underlying JS function tries hard to make a date from the input. You can enter a date +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 +formatting template. (For example, try 2018 Jan 10). +\end{minipage}\medskip + + +\textbf{Note:} In the discussion that follows, we assume you are using +\app{Adobe Acrobat DC} (or prior), \app{Adobe Reader DC} (or prior) or +\app{PDF-XChange Editor}. These PDF viewers support the JavaScript used +by this package.\medskip + +\textbf{Discussion:} Enter an \emph{invalid date} into each field (such as +the number 17), and \emph{commit} that number to the field. There are several +ways of committing form data: (1) press the \uif{Enter} key; (2) tab out of the +field; (3) click or tap outside the field; and (4) move to another +page.\footnote{Apparently, \app{PDF-XChange Editor} does not commit field +data when the page is turned, unlike the Adobe PDF viewer.} The behavior of +the field is the same for cases (2)--(4); in those cases, the field loses +focus (or is blurred). In the first case, the data is committed, but +\emph{not blurred}. This latter case is a bit of a problem because the blur +event has JavaScript that sets the field text color, as appropriate.\medskip + +In the above two fields, enter the number 17 (or any invalid date) and commit +the data using method (2) or (3); now repeat the exercise for the two fields, +but commit using method (1). Do you notice a difference?\medskip + +\textbf{Discussion of (2) and (3):} This is the usual case; after the alert +dialog box is dismissed, the fields are grayed out again. That's the effect +desired by this package.\medskip + +\textbf{Discussion of (1):} When the data is committed by pressing the +\uif{Enter} key and the alert box is dismissed, for the field on the left +`yyyy/mm/dd' appears in black, whereas, for the field on the right, the +string `continue editing' appears in black. In each case, you can click +within the field and continue editing the date. Use methods (2) or (3) to +commit your final response. Of the two fields, the behavior of the field on +the right is the preferred one.\medskip + +The behavior of the field on the right requires some special code. +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small,numbers=left,numbersep=9pt,commandchars={!~@}] +\textField[\textColor{\matchGray} + \TU{Enter a date of your choosing} + \AA{% + \AAOnFocus{\JS{\FocusToBlack}} + \AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r + \KeyToGray} + \AAFormat{\DateFmtEx("yyyy/mm/dd");\r + \FmtToGray{yyyy/mm/dd}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} % <-!normalfont~ required for !app~PDF-XChange Editor@@ +}]{Datefield2}{1in}{11bp} +\end{Verbatim} +The code above is identical to that of the left-hand field with two +exceptions, marked above by (5) and~(7). On these lines, the commands +\cs{DateKeyEx} and \cs{DateFmtEx} are used (instead of the Adobe built-in +functions directly). When these two are inserted, then we get the behavior of +the field on the right on page 1.\medskip + + + +When the changes shown in lines~(5) and~(7) are made, you can customize the +behavior of the field when the date is committed by pressing the \uif{Enter} +key.\medskip + +\EnterCommitFailEvent{event.value=("weiter bearbeiten");} +\textField[\textColor{\matchGray} + \TU{Enter a date of your choosing} + \AA{% + \AAOnFocus{\JS{\FocusToBlack}} + \AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r + \KeyToGray} + \AAFormat{\DateFmtEx("yyyy/mm/dd");\r + \FmtToGray{yyyy/mm/dd}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Datefield3}{1in}{11bp}\medskip + +Here, we use \cs{EnterCommitFailEvent} and declare, +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] +\EnterCommitFailEvent{event.value=("weiter bearbeiten");} +\end{Verbatim} +which changes the text string that appears when \uif{Enter} is pressed for an invalid date.\medskip + +\EnterCommitFailEvent{% + event.target.strokeColor=color.red; + event.value=(event.target.savevalue);} +\CommitSuccessEvent{event.target.strokeColor=color.black;} +We can get a different effect with +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] +\EnterCommitFailEvent{% + event.target.strokeColor=color.red; + event.value=(event.target.savevalue);} +\CommitSuccessEvent{event.target.strokeColor=color.black;} +\end{Verbatim} +The action declared by \cs{EnterCommitFailEvent} is to change the border +color to red, and secondly, to set the value of the field to the saved value +(\texttt{event.target.savevalue}). The property \texttt{savevalue} is defined +through the use of the special commands \cs{DateKeyEx} and \cs{DateFmtEx}. +The action of \cs{CommitSuccessEvent} returns the fields border color to +black.\medskip + +\textField[\textColor{\matchGray} + \TU{Enter a date of your choosing} + \AA{% + \AAOnFocus{\JS{\FocusToBlack}} + \AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r + \KeyToGray} + \AAFormat{\DateFmtEx("yyyy/mm/dd");\r + \FmtToGray{yyyy/mm/dd}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Datefield4}{1in}{11bp}\medskip + +Now, when an invalid date is entered using the \uif{Enter} key, the border +color of the field is changed to red to indicate to the user that the date +in invalid and needs to be modified. Tabbing or clicking outside the field, as +usual, blurs the field; any invalid date is removed and the grayed hint +appears.\medskip + +To return to the default declarations, expand \verb!\EnterCommitFailEvent{}! and +\verb!\CommitSuccessEvent{}!. The underlying default actions are, +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] +\newcommand\FailStringDef{continue editing} +\newcommand\EnterCommitFailDef{event.value=("\FailStringDef");} +\end{Verbatim} +A localization of language can be performed by redefining +\cs{FailStringDef} +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] +\renewcommand\FailStringDef{weiter bearbeiten} +\end{Verbatim} + +The next example changes the border, the text color, and the error message.\medskip + +\EnterCommitFailEvent{\t + event.target.strokeColor=color.red;\r\t\t + event.target.textColor=color.red;\r\t\t + event.value=("needs editing"); +} +\CommitSuccessEvent{\t\t + event.target.strokeColor=color.black; +} + +\noindent +\textField[\textColor{\matchGray} + \TU{Enter a date of your choosing}\AA{% + \AAOnFocus{\JS{\FocusToBlack}} +% using a customized version of Adobe built-in functions, with LaTeX access + \AAKeystroke{\DateKeyEx("yyyy/mm/dd");\r + \KeyToGray} + \AAFormat{\DateFmtEx("yyyy/mm/dd");\r + \FmtToGray{yyyy/mm/dd}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Datefield5}{1in}{11bp}\qquad(enter `17' then press enter)\medskip + +This same scheme should work for all the built-in Acrobat formats, let's look +at the number format.\medskip + +\EnterCommitFailEvent{}\CommitSuccessEvent{} +\textField[\TU{Enter an integer} + \textColor{\matchGray}\AA{% + \AAKeystroke{\NumKey(0,1,0,0,"",true);\r\KeyToGray} + \AAFormat{\NumFmt(0,1,0,0,"",true);\r + \FmtToGray{Enter an Integer}} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Integer}{1in}{11bp}\medskip + +\textbf{Creating a Percent text field.}\medskip + +\textField[\textColor{\matchGray}\AA{% + \AAKeystroke{\PercentKey(2,1);\r + \KeyToGray} + \AAFormat{\PercentFmt(2,1);\r + \FmtToGray{Enter a number}} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Percent}{2in}{11bp} (don't enter the percent symbol \%)\medskip + +\textbf{Creating a Phone Number text field.}\medskip + +Enter a phone number: \textField[\textColor{\matchGray}\AA{% + \AAKeystroke{\SpecialKey(2);\r + \KeyToGray} + \AAFormat{\SpecialFmt(2);\r + \FmtToGray{(123) 456-7890}} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Phone}{2in}{11bp}\medskip + +The underlying JS function tries hard to make a phone number out of the input. The phone number can +be entered in any recognized format; even something like 1234567890 is formatted.\medbreak + +\textbf{Creating a Custom time format text field.}\medskip + +\def\parentt{(tt)} % necessary to insert within arg of \TimeFmtEx +\textField[\textColor{\matchGray}\AA{% + \AAKeystroke{\TimeKey(0);\r + \KeyToGray} + \AAFormat{\TimeFmtEx("h:MM \parentt");\r + \FmtToGray{Enter a time}} + \AAOnFocus{\JS{\FocusToBlack}} + \AAOnBlur{\JS{\BlurToBlack}} + \AACalculate{\CalcToGray} +}]{Time}{2in}{11bp}\kern1bp\pushButton[\TU{Push to Use Current Time} +\CA{UCT}\A{\JS{% + var cTime=util.printd("h:MM",new Date());\r + var f=this.getField("Time");\r + f.value=cTime; +}}]{pbTime}{}{11bp}\medskip + +Detailed information on formatting with the built-in functions of \app{Acrobat} may be found at +the \href{http://blog.acrotex.net}{Acro\negthinspace\TeX\space Blog}; in particular, see the article +\url{http://www.acrotex.net/blog/?p=218}. + +\end{document} diff --git a/macros/latex/contrib/grayhints/examples/gh-fmts-hyperref.tex b/macros/latex/contrib/grayhints/examples/gh-fmts-hyperref.tex new file mode 100644 index 0000000000..ea8f2337ac --- /dev/null +++ b/macros/latex/contrib/grayhints/examples/gh-fmts-hyperref.tex @@ -0,0 +1,257 @@ +\documentclass{article} +\usepackage[designiv]{web} +\usepackage[usehyforms]{grayhints} +\usepackage{fancyvrb} + + +\addtoWebHeight{1in} +\def\cs#1{\texttt{\char`\\#1}} +\let\app\textsf +\let\pkg\textsf +\let\uif\textsf +\parindent0pt + +%\EnterCommitFailEvent{\jsT\jsT +% event.target.strokeColor=color.blue;\jsR\jsT\jsT +% event.value=(event.target.savevalue);} +%\CommitSuccessEvent{event.target.strokeColor=color.red;} + + +\begin{document} +\begin{Form} +\begin{center}\large\bfseries Gray Hints - Formats +\end{center} +The `gray hint' technique requires modifications to the Format, +Keystroke, OnFocus, OnBlur, and Calculate events. Refer to \texttt{gh-fmts-eforms} for a more +discussion of these fields.\medskip + +\renewcommand\LayoutTextField[2]{#2} +\renewcommand\LayoutChoiceField[2]{#2} + +\TextField[% + name={Datefield1}, + height=11bp, + width=1in, + color={\matchGray}, + keystroke={AFDate_KeystrokeEx("yyyy/mm/dd");\jsR + \KeyToGray}, + format={AFDate_FormatEx("yyyy/mm/dd");\jsR + \FmtToGray{yyyy/mm/dd}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\kern2bp\quad +\TextField[% + name={Datefield2}, + height=11bp, + width=1in, + color={\matchGray}, + keystroke={\DateKeyEx("yyyy/mm/dd");\jsR + \KeyToGray}, + format={\DateFmtEx("yyyy/mm/dd");\jsR + \FmtToGray{yyyy/mm/dd}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\medskip + +\textbf{Note:} In the discussion that follows, we assume you are using +\app{Adobe Acrobat DC} (or prior), \app{Adobe Reader DC} (or prior) or +\app{PDF-XChange Editor}. These PDF viewers support the JavaScript used +by this package.\medskip + +The behavior of the field on the right requires some special code. +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small,numbers=left,numbersep=9pt,commandchars={!~@}] +\TextField[% + name={Datefield2}, + height=11bp,width=1in,charsize=9bp, + color={\matchGray}, + keystroke={\DateKeyEx("yyyy/mm/dd");\jsR + \KeyToGray}, + format={\DateFmtEx("yyyy/mm/dd");\jsR + \FmtToGray{yyyy/mm/dd}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} % <-!normalfont~ required for !app~PDF-XChange Editor@@ +]{}\end{Verbatim} +The code above is identical to that of the left-hand field with two +exceptions, marked above by (5) and~(7). On these lines, the commands +\cs{DateKeyEx} and \cs{DateFmtEx} are used (instead of the Adobe built-in +functions directly). When these two are inserted, then we get the behavior of +the field on the right on page 1.\medskip + +When the changes shown in lines~(5) and~(7) are made, you can customize the +behavior of the field when the date is committed by pressing the \uif{Enter} +key.\medskip + +\EnterCommitFailEvent{event.value=("weiter bearbeiten");} +\TextField[% + name={Datefield3}, + height=11bp,width=1in,charsize=9bp, + color={\matchGray}, + keystroke={\DateKeyEx("yyyy/mm/dd");\jsR + \KeyToGray}, + format={\DateFmtEx("yyyy/mm/dd");\jsR + \FmtToGray{yyyy/mm/dd}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\medskip + +Here, we use \cs{EnterCommitFailEvent} and declare, +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] +\EnterCommitFailEvent{event.value=("weiter bearbeiten");} +\end{Verbatim} +which changes the text string that appears when \uif{Enter} is pressed for an invalid date.\medskip + +\EnterCommitFailEvent{% + event.target.strokeColor=color.blue; + event.value=(event.target.savevalue);} +\CommitSuccessEvent{event.target.strokeColor=color.red;} +We can get a different effect with +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] +\EnterCommitFailEvent{% + event.target.strokeColor=color.blue; + event.value=(event.target.savevalue);} +\CommitSuccessEvent{event.target.strokeColor=color.black;} +\end{Verbatim} +The action declared by \cs{EnterCommitFailEvent} is to change the border +color to blue, and secondly, to set the value of the field to the saved value +(\texttt{event.target.savevalue}). The property \texttt{savevalue} is defined +through the use of the special commands \cs{DateKeyEx} and \cs{DateFmtEx}. +The action of \cs{CommitSuccessEvent} returns the fields border color to +black.\medskip + +\TextField[% + name={Datefield4}, + height=11bp,width=1in,charsize=9bp, + color={\matchGray}, + keystroke={\DateKeyEx("yyyy/mm/dd");\jsR + \KeyToGray}, + format={\DateFmtEx("yyyy/mm/dd");\jsR + \FmtToGray{yyyy/mm/dd}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\medskip + +Now, when an invalid date is entered using the \uif{Enter} key, the border +color of the field is changed to blue to indicate to the user that the date +in invalid and needs to be modified. Tabbing or clicking outside the field, as +usual, blurs the field; any invalid date is removed and the grayed hint +appears.\medskip + +To return to the default declarations, expand \verb!\EnterCommitFailEvent{}! and +\verb!\CommitSuccessEvent{}!. The underlying default actions are, +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] +\newcommand\FailStringDef{continue editing} +\newcommand\EnterCommitFailDef{event.value=("\FailStringDef");} +\end{Verbatim} +A localization of language can be performed by redefining +\cs{FailStringDef} +\begin{Verbatim}[xleftmargin=15pt,fontsize=\small] +\renewcommand\FailStringDef{weiter bearbeiten} +\end{Verbatim} + +The next example changes the border, the text color, and the error message.\medskip + +\EnterCommitFailEvent{\jsT + event.target.strokeColor=color.blue;\jsR\jsT\jsT + event.target.textColor=color.blue;\jsR\jsT\jsT + event.value=("needs editing"); +} +\CommitSuccessEvent{\jsT\jsT + event.target.strokeColor=color.red; +} + +\noindent +\TextField[% + name={Datefield5}, + height=11bp,width=1in,charsize=9bp, + color={\matchGray}, + keystroke={\DateKeyEx("yyyy/mm/dd");\jsR + \KeyToGray}, + format={\DateFmtEx("yyyy/mm/dd");\jsR + \FmtToGray{yyyy/mm/dd}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\qquad(enter `17' then press enter)\medskip + + + +This same scheme should work for all the built-in Acrobat formats, let's look +at the number format.\medskip + +\EnterCommitFailEvent{}\CommitSuccessEvent{} +\TextField[% + name=Integer, + height=11bp,width=1in,charsize=9bp, + color={\matchGray}, + keystroke={\NumKey(0,1,0,0,"",true);\jsR\KeyToGray}, + format={\NumFmt(0,1,0,0,"",true);\jsR + \FmtToGray{Enter an Integer}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\smallskip + +\textbf{Creating a Percent text field.}\medskip + +\TextField[% + name=Percent, + height=11bp,width=2in,charsize=9bp, + color=\matchGray, + keystroke={\PercentKey(2,1);\jsR + \KeyToGray}, + format={\PercentFmt(2,1);\jsR + \FmtToGray{Enter a number}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{} (don't enter the percent symbol \%)\medskip + +\textbf{Creating a Phone Number text field.}\medskip + +Enter a phone number: \TextField[% + name=Phone, + height=11bp,width=2in,charsize=9bp, + color=\matchGray, + keystroke={\SpecialKey(2);\jsR + \KeyToGray}, + format={\SpecialFmt(2);\jsR + \FmtToGray{(123) 456-7890}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\medskip + +The underlying JS function tries hard to make a phone number out of the input. The phone number can +be entered in any recognized format; even something like 1234567890 is recognized and formatted.\medbreak + +\textbf{Creating a Custom time format text field.}\medskip + +\def\parentt{(tt)} % necessary to insert within arg of \TimeFmtEx +\TextField[% + name=Time, + height=11bp,width=2in,charsize=9bp, + color=\matchGray, + keystroke={\TimeKey(0);\jsR + \KeyToGray}, + format={\TimeFmtEx("h:MM \parentt");\jsR + \FmtToGray{Enter a time}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\quad\PushButton[% + height=11bp, + name=pbtime, + onclick={var cTime=util.printd("h:MM",new Date());\jsR + var f=this.getField("Time");\jsR + f.value=cTime;}]{UCT}\medskip + +Detailed information on formatting with the built-in functions of \app{Acrobat} may be found at +the \href{http://blog.acrotex.net}{Acro\negthinspace\TeX\space Blog}; in particular, see the article \url{http://www.acrotex.net/blog/?p=218}. + +\end{Form} +\end{document} diff --git a/macros/latex/contrib/grayhints/examples/gh-hyperref.tex b/macros/latex/contrib/grayhints/examples/gh-hyperref.tex new file mode 100644 index 0000000000..862b9d30dc --- /dev/null +++ b/macros/latex/contrib/grayhints/examples/gh-hyperref.tex @@ -0,0 +1,151 @@ +\documentclass{article} +\usepackage[designiv]{web} +\usepackage[usehyforms]{grayhints} + +\addtoWebHeight{1in} +\def\cs#1{\texttt{\char`\\#1}} +\parindent0pt + +%\EnterCommitFailEvent{\jsT\jsT +% event.target.strokeColor=color.blue;\jsR\jsT\jsT +% event.value=(event.target.savevalue);} +%\CommitSuccessEvent{event.target.strokeColor=color.red;} + + +\begin{document} +\begin{Form} +\begin{center}\large\bfseries Gray Hints +\end{center} +The `gray hint' technique requires modifications to the Format, +Keystroke, OnFocus, OnBlur, and Calculate events.\medskip + +\renewcommand\LayoutTextField[2]{\mbox{#2}} +\renewcommand\LayoutChoiceField[2]{\mbox{#2}} + +\TextField[% + name={Name.First}, + height=11bp, + width=2in, + color={\matchGray}, + keystroke=\KeyToGray, + format={\FmtToGray{First Name}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{First Name:}\quad +\TextField[% + name={Name.Laat}, + height=11bp, + width=2in, + color={\matchGray}, + keystroke=\KeyToGray, + format={\FmtToGray{Last Name}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\medskip + +\TextField[% + name=Datefield, + height=11bp, + width=1in, + color={\matchGray}, + keystroke={\DateKeyEx("yyyy/mm/dd");\jsR\KeyToGray}, + format={\DateFmtEx("yyyy/mm/dd");\jsR\FmtToGray{yyyy/mm/dd}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\enspace$\Leftarrow$\enspace +\parbox{\linewidth-1in-\widthof{\enspace$\Leftarrow$\enspace}} +{\small Refer to \texttt{gh-fmts-hyperref.tex} for additional discussion of +fields requiring special formatting.}\medskip + +The next three fields perform calculations, the last one is the sum of the +first two. These are fields formatted as numbers. To prevent `Total' field +from displaying a zero (0) when the dependent fields are empty (and to +display its gray hint instead), a document JavaScript function was developed, +named \texttt{AllowCalc(cArray)}. This function returns \texttt{true} if any +of the fields listed in \texttt{cArray} has a value and returns +\texttt{false}, otherwise.\smallskip + +\TextField[% + name=Integer.First, + height=11bp, + width=1in, + color={\matchGray}, + keystroke={\NumKey(0,1,0,0,"",true);\KeyToGray}, + format={\NumFmt(0,1,0,0,"",true); \FmtToGray{First Integer}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\smallskip + +\TextField[% + name=Integer.Second, + height=11bp, + width=1in, + color={\matchGray}, + keystroke={\NumKey(0,1,0,0,"",true); \KeyToGray}, + format={\NumFmt(0,1,0,0,"",true); \FmtToGray{Second Integer}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}\smallskip + +% The use of \jsR (\jsT) is for editing purposes, should you have Acrobat or PDF-XChange Pro; otherwise, they are optional +\TextField[% + name=TotalNumber, + height=11bp, + width=1in, + color={\matchGray}, + keystroke={\NumKey(0,1,0,0,"",true);\jsR\KeyToGray}, + format={\NumFmt(0,1,0,0,"",true);\jsR\FmtToGray{Total}}, + calculate={var cArray=new Array("Integer");\jsR + if (AllowCalc(cArray))\SimpleCalc("SUM", cArray );\jsR\CalcToGray}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack} +]{}\medskip + +The gray hint technique can apply to editable combo boxes as well.\smallskip + +\ChoiceMenu[% + name=combo, + combo, + width=1.65in, + height=11bp, + edit, + color={\matchGray}, + keystroke={\KeyToGray}, + format={\FmtToGray{Enter your favorite food}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{}{Meat,Potatoes,Rice,Onions,Pickles}\medskip + +The color scheme of the gray hints can be changed using +\cs{normalGrayColors}. The initial value of \cs{textColor}, which sets the +color of the text, must match, for appearance sake, the choice for the gray +color; for this reason, the \cs{matchGray} command was developed.\smallskip + + +\normalGrayColors{color.blue}{color.magenta} + +\TextField[% + name=Pet, + width=1in, + height=11bp, + color={\matchGray}, + keystroke={\KeyToGray}, + format={\FmtToGray{Pet's name}}, + onfocus={\FocusToBlack}, + onblur={\BlurToBlack}, + calculate={\CalcToGray} +]{Pet}\medskip + +\PushButton[% + height=11bp, + name=reset, + onclick={this.resetForm();}]{Reset} + +\end{Form} +\end{document} |