mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
PDF-form.lyx: add example how to validate numbers
This commit is contained in:
parent
41b39ff835
commit
d20bc1c883
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
\pdfcatalog{/AA \the\pdflastobj\space 0 R}
|
\pdfcatalog{/AA \the\pdflastobj\space 0 R}
|
||||||
\begin{insDLJS}[exaaae]{exaaae}{JavaScript}
|
\begin{insDLJS}[exaaae]{exaaae}{JavaScript}
|
||||||
|
|
||||||
function validateTime(){
|
function validateTime(){
|
||||||
this.delay = true;
|
this.delay = true;
|
||||||
if((event.value == "u") || (event.value == "unlimited")) {
|
if((event.value == "u") || (event.value == "unlimited")) {
|
||||||
@ -33,6 +34,19 @@
|
|||||||
}
|
}
|
||||||
this.delay = false;
|
this.delay = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkNumber() {
|
||||||
|
event.rc = true;
|
||||||
|
if (!Number(event.value))
|
||||||
|
{
|
||||||
|
app.alert("Value must be a number!");
|
||||||
|
event.value = "";
|
||||||
|
} else {
|
||||||
|
event.target.textColor = color.green;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
\end{insDLJS}
|
\end{insDLJS}
|
||||||
|
|
||||||
% if pdflatex is used
|
% if pdflatex is used
|
||||||
@ -1431,7 +1445,7 @@ Here are some examples:
|
|||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Text Field Style
|
\begin_layout Text Field Style
|
||||||
print, bordercolor=red,borderstyle=U, backgroundcolor=lightgray, color=lime,
|
print, bordercolor=red, borderstyle=U, backgroundcolor=lightgray, color=lime,
|
||||||
maxlen=10, align=2, charsize=16pt
|
maxlen=10, align=2, charsize=16pt
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
@ -2749,7 +2763,11 @@ Note:
|
|||||||
\emph on
|
\emph on
|
||||||
All
|
All
|
||||||
\emph default
|
\emph default
|
||||||
JavaScript funtions must be inserted into the same insDLJS environment.
|
JavaScript funtions must be inserted into the same
|
||||||
|
\family sans
|
||||||
|
insDLJS
|
||||||
|
\family default
|
||||||
|
environment.
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\end_inset
|
\end_inset
|
||||||
@ -2928,6 +2946,93 @@ name=to,width=10em
|
|||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
\begin_inset VSpace bigskip
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
To check and assure that the user only enters a number to a text field you
|
||||||
|
can for example use this JavaScript code:
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
\begin_inset listings
|
||||||
|
lstparams "language=TeX"
|
||||||
|
inline false
|
||||||
|
status open
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
function checkNumber() {
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
event.rc = true;
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
if (!Number(event.value)) {
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
app.alert("Value must be a number!");
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
event.value = "";
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
} else {
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
event.target.textColor = color.green;
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
An example text field:
|
||||||
|
\begin_inset Flex TextField
|
||||||
|
status open
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
\begin_inset Argument 1
|
||||||
|
status open
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
name=test, align=1, validate={checkNumber();}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Standard
|
\begin_layout Standard
|
||||||
|
Loading…
Reference in New Issue
Block a user