These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Required field loop

Papote
Registered: Feb 18 2011
Posts: 9

I have two fields: field1 and field2. Both are set as “User Entered - Required”. I am trying to enforce that they cannot be empty. I made the following routine, but when I leave field1 empty and click on the field2 (which is also empty) I get stuck in an infinite loop of the same error message from both fields.

Using FormCalc on the Exit event:
if ($.isNull) then
xfa.host.messageBox("Field cannot be blank!")
$host.setFocus ($.name)
endif

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Try using the "Validate" event. This is the correct location for validating a field value.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Papote
Registered: Feb 18 2011
Posts: 9
Tried using the same code on the validate event, but I get the error messages for both fields when the PDF is opened and nothing happens when I click on both fields.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The validate event is run when data is entered into the fields. The last value evaluated in the validate event must be a true/false statement, Which tells acrobat whether or not the validation passed.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Papote
Registered: Feb 18 2011
Posts: 9
Not exactly sure I understand. Could you provide an example?
Thanks.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The problem with your code right now is that focus is being constantly moved between the fields because the enter and exit events follow each other. To break this cycle the testing code needs to be moved to a location that only gets called when there is a change in the field value. Since the code is doing a validation, the validate event it perfect.

Just enter this code into the validate event. Set the validate message in the Object tab.

if($.isNull) then
$host.messageBox("Field cannot be blank!")
$host.setFocus($.name);
else
1
endif


Of course, now you have another problem. This code is also called when the form is opened. Another approach is to put it in the change event.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script