1

Consider the MWE below, I want to validate the date entry as well as the Email addresses to be entered as they should be using the validation option that is only briefly mentioned in the manual of the hyperref package:

validate JavaScript code to validate the entry

MWE:

\documentclass{scrartcl}
\usepackage{xcolor}
\usepackage{hyperref}
\begin{document}
\begin{Form}
\minisec{Time schedule:}
\TextField[backgroundcolor=gray!10,borderwidth=0,maxlen=10,value=01/09/2015,width=6em]{Proposed starting date of the study:}\\
\noindent\TextField[backgroundcolor=gray!10,borderwidth=0,maxlen=10,value=31/12/2016,width=6em]{Proposed completion date of the study:}\\
\TextField[backgroundcolor=gray!10,borderwidth=0,maxlen=10,value=user.name@acount.name,width=20em]{E-Mail:}\\
\end{Form}
\end{document}

Output:
enter image description here

  • Validation requires JavaScript and is basically restricted to Adobe Acrobat – user31729 Sep 7 '15 at 19:53
  • 1
    @ChristianHupfer, that's true and which I am after. Any example for JavaScript code would be much appreciated. – doctorate Sep 8 '15 at 5:49
  • Is it the javascript you need help with? If so, I am not sure this is on-topic. But whether it is on-topic or not, this is probably not the best place to ask the question and you would likely get more help by asking on a site where javascript is a frequent topic of discussion. – cfr Sep 10 '15 at 0:53
1

If you know the Javascript to validate a date or an email (I don't) you can adapt this example that I put together by reverse engineering some examples in the Acrobat specification (you won't find this in the hyperref documentation and I couldn't find any preexisting example in the context of hyperref).

\documentclass{article}
\usepackage{hyperref}
\usepackage{pdfcomment} %why I need this?
\begin{document}  
    \TextField[
        validate = {
            event.rc = true; 
            if(event.value != "A" && event.value != "B"){ /*your validation code goes here*/
                app.alert("Error, value must be A or B"); 
                event.rc=false;
            }
        }
    ]{A or B:}
\end{document}

I tested it with Acrobat 9.4.1.

This is the first time I code in Javascript, I am not sure if one can load libraries or do other fancy stuff from the Javascript embedded in the Acrobat Reader. If you post your Javascript code I will learn more.

I cannot find the way to verify the code for syntax errors, if there is a syntax error the script is basically ignored. For example a tiny mistake can make the code not run at all.

Code based on: http://khkonsulting.com/2012/11/validating-field-contents/

  • this can be a good start to find an answer. Where in the PDF do you receive the alert message? it would be interesting if there is someway to integrate jQuery plugin of JavaScrirpt into this code. – doctorate Sep 10 '15 at 4:42
  • I don't get any feedback when I run your code, I don't have any clue whether any JavaScript code is running in the PDF. – doctorate Sep 10 '15 at 4:48
  • It is a good start to find the answer. The alert happens as a pop up dialog with the message "Error, value must be A or B". Please let me know if you know how to include plugins and libraries (I am very illiterate on web technologies). You don't get any feedback because the code has a syntax error (the comment //... doesn't work) which makes the code invalid and silently fails (first lesson learnt). I corrected the code now. – alfC Sep 10 '15 at 5:16
  • some information on js and jQuery formden.com/blog/validate-contact-form-jquery . Did it work for you? – alfC Sep 10 '15 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.