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

setFocus and Validation Question

rw
Registered: Sep 2 2008
Posts: 23
Answered

Hi,

I have two questions about xfa.event.setFocus() and validation

1. Is there any way to determine the next field in the tab order so I can use setFocus to jump to the next field without having to put the real field name in the setFocus?

2. In my JavaScript Exit event I check the user's input and if incorrect I do a setFocus back to that field so they can try again.

When the user triggers the Exit event by tabbing, the focus works and ends up highlighting the bad data they just entered.

When the user triggers the Exit event by hitting the Enter Key the focus does not work and nothing is highlighted. I can force it to work by checking for the Enter Key with a xfa.event.commitKey and doing a setFocus to the next field in tab order and then doing a setFocus back to the original field that had the error. This does work except with a Date/Time field the setFocus back to the original field get hung up and does not work until I mouse click on another field. Why is that?

Is there a better way to do this?

Here's my sample JavaScript

F.P5.WRKPhone::exit - (JavaScript, client)
var ValPhone = /^(\d{10})$/;
if (this.rawValue != null && this.rawValue != "") {
if (! ValPhone.test(this.rawValue)) {
if (xfa.event.commitKey != 2) {
xfa.host.setFocus(this); }
else {
xfa.host.setFocus(F.P1.EmgPhone);
app.setTimeOut("xfa.host.setFocus('" + this.somExpression + "');", 10);
}
}
}

Thanks a lot for any help!

Ron

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You're code is way to complex. Why don't you use the Validate event to validate the data? That's what it's for. The set focus event works just fine for resetting the focus on this field, and it's only called when the user is really entering new data.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

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

rw
Registered: Sep 2 2008
Posts: 23
thomp,

I put my validate script in the Validate Event as you suggested and did a xfa.host.setFocus if the data was bad to set the cursor back to the field for another try. I then returned true or false, so an error message was given if the data did not validate.

I found out the setFocus does not work in the Validate Event when I let the the Adobe software throw a validate error. The error message seems to cancel out my setFocus. But, the setFocus works fine when I put out my own error message, then do the setFocus (all in the Validate Event). I had to return true so the system didn't throw the error message, since I handled the error with my own message. This method works fine for date also.

Maybe I misunderstood your answer or I don't know what I'm doing. I understood you to say put my check for valid phone number and the setFocus in the Validate Event. And that I don't need to use the exit event for what I want to do. Any idea?

Thanks

Ron
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I haven't done extensive testing on this but I think you are on the right track. To use the setFocus function you need to get around the default validate actions, so you need to return true from the validate event. The exit event fires when the field loses focus, but the validate event fires when the field value changes. So don't use the exit event for this.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

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

madfox
Registered: Feb 13 2009
Posts: 8
Hello rw

I am quiet new to the LiveCycle, and am currently handling quiet similar problem as you had. From the posts I get that you managed to solve it. Could you then paste the code you used for the validate event? I'd appreciate it very much.