I'm creating an interactive pdf form with the hyperref
package. The form is quite comprehensive, so the current goal is to only show parts that are relevant to the specific user. For example, the user indicates that he is male –> only the items that concern males are displayed.
Usually it's not difficult to display only certain parts of a document, e.g. using the ifthen
package:
\documentclass{article}
\usepackage{ifthen}
\begin{document}
\newboolean{boolvar}
\setboolean{boolvar}{false}
\ifthenelse{\boolean{boolvar}}{show if true}{show if false}
\end{document}
I'm lost, however, when it comes to combining variables like that with user input from form fields. Using JavaScript and the insdljs
package, I've gotten as far as hiding form fields, but not text outside of these form fields: (Note: insdljs
is not part of TeX Live, but available here)
\documentclass{article}
\usepackage[pdftex]{hyperref}
\usepackage[pdftex]{insdljs}
\begin{insDLJS}{mydljs}{some comment}
function hide(){
if(this.getField("somefield").display == display.visible){
this.getField("somefield").display = display.hidden;
} else{
this.getField("somefield").display = display.visible;
}
}
\end{insDLJS}
\begin{document}
\begin{Form}
\PushButton[onclick={hide();}]{Hide/Show}\\
\TextField[name=somefield, width=4em]{Any way to hide e.g. this text?}
\end{Form}
\end{document}
Hiding form fields like that is very handy, but I'd like to apply that to entire tables or sections. Any idea? Thanks!
Best Answer
I don't know actually, but I conducted small research, and think that you can't hide it, you can do nothing with it, at all (without a little trick, of course)
First of all, I create a simple example and open it in Adobe Acrobat. I see, that a field and a label independent. And there is no any TextField properties that can change the label. Textfield it's field, label it's text.
If you really wanna hide label, you can do something like this:
you hide field 'test', and 'tf1' is visible
field 'test' is visible, 'tf1' to hide
It works, but I don't sure, that you need it.
In order to verify that we can't change the text, I have played with the buttons. Using javascript API for Acrobat Reference I found
buttonGetCaption
andbuttonSetCaption
methods, to change label (seems like caption), it works not as I expected:before click: after:
So, i think it's bad idea to hide text, but you can easily hide Textfield, lets do it!
before:
after:
Another solution of this problem to replace labels with defaultValue, example:
before click:
after:
You can hide it as before.