\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}