David,

Here's some code I have used for checking for required fields.  

In the first set of code, the user can't print the form using the "Print" button that 
I put on the form until all required fields are entered.

The second set of code requires that the required fields have a name that begins with 
the 8 characters "required".

var f1 = this.getField("SSNUM");
var f2 = this.getField("TIMEPM");
if (f1.value == "")
        {app.alert("Social Security Number is a required field!")
        if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0) 
                // Version specific operation:
                f1.setFocus();}
else
        {
        if (f2.value == "")
                {app.alert("Time is a required field!")
                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0) 
                        // Version specific operation:
                        f2.setFocus();}
        else
                app.execMenuItem("Print");
        }

// Enumerate through all of the fields in the document.
for (var i = 0; i < this.numFields; i++)
{
if (this.getNthFieldName(i).substring(0,8)  == "required")
        {
        var f1 = this.getField(this.getNthFieldName(i));
        if (f1.value == "")
                {
                app.alert(this.getNthFieldName(i) + " is a required field!")
                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0) 
                        // Version specific operation:
                        f1.setFocus();
                }
        }
}

-----Original Message-----
From:   [EMAIL PROTECTED] on behalf of David Lindblad
Sent:   Sat 4/3/2004 6:46 AM
To:     [EMAIL PROTECTED]
Cc:     
Subject:        Re: [PDF-Forms] Required fields

PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/
__________________________________________________________________

> If the user will have to fill out any subsequent page, the most 
> obvious place to check the completeness of the first page would be the 
> pageClose event of that first page. Here, you would check the fields 
> which you want to have filled, and display them to the user. You 
> better ask the user if it is OK to keep the fields empty, in order to 
> let the user go to the other pages, and then come back to the first 
> one.

You mention "setFocus" as a method below, how would I go about checking 
the fields?

>
> So, if you encounter a non-filled out field, you could for one mark it 
> visually (for example by making a big fat red border around it (and 
> reset it, of course, when it is validated the next time...)), and you 
> could also set the focus to this field. You would do that with the 
> setFocus() field object method. Note that this method is available 
> only from Acrobat (Reader) 4.05 on, which means that you might have to 
> check for the viewer version first.
>
> If I remember correctly, it is the order of creation of the fields 
> which gets followed when checking the "required" flag. This order may 
> or may not be logical and predictable. It might therefore be a better 
> idea to do your own "required" routine, by keeping the field names of 
> the fields you require in an array you define when opening the 
> document. Such an array could also be used for other purposes, such as 
> printing. AND, it would give you much more control over the order of 
> the validation and how you present the results.
>
> Hope, this can help.

Max, could you suggest some resource(s) for learning javascript 
specific to pdf's.  I recognize some of what you have suggested above, 
(even know how to implement some of it :) but would really like to 
learn more.

Thanks

Dave 


To change your subscription:
http://www.pdfzone.com/discussions/lists-pdfforms.html



<<winmail.dat>>

Reply via email to