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

Keeping focus on a field that fails validation

cl5792
Registered: Jul 17 2008
Posts: 53
Answered

I have a field that must be > than the current date. I have the validation working correctly and displaying a message when it fails. However, the user can click on the next field without resolving the validation failure. How can I prevent the user from exiting the field until the issue is resolved and the correct data entered.

I am using Livecycle 8.0

I have this script in the validation event for the field to test (DateRequested)

DateRequested.rawValue>DateNow.rawValue;

Any help is greatly appreciated!

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you search the forum for "validation" and "focus" you'll find lots of related posts.

Here's some code for one technique:
Place this code in the Validate event
this.tst = this.rawValue > DateNow.rawValue;this.tst || Boolean(this.execEvent("exit"));

It saves the test result in a variable attached to the field object, and if the validation fails it forces the Exit event code to be called.

Place this code in the Exit Event
if(!(this.tst))xfa.host.setFocus(this.somExpression);

This code forces the focus to stay on the field until a valid result is entered. It's a bit obnoxious though since it takes control away from the user.

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

cl5792
Registered: Jul 17 2008
Posts: 53
Thank you so much, this was exactly what I needed.
pavankumarreddyr
Registered: Dec 8 2008
Posts: 18
Hi Thomp,

I got few required fields in my PDF which got nearly 15 pages.

When the user trying to submit the form i am showing a message popup if validation fails for a particular field, but it stays in the same page where i click submit button, in this case user has to go back to that particular page to fill that field with a valid input.

My requirement is to get focus to that particular field(to the page where field validation failed) where validation got failed, so that user no need to scroll back to that page manually.

Is there any way to do this?

Thanks in advance

R pavan kumar reddy

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Of course there is a way, anything is possible. Use a script to do a pre-submit validation on all the required form fields. Then set the focus onto the required field that has a problem.

This may not be enough, I haven't test out the idea myself. However, you can find out the page a fields is on and set the current page from functions in the "xfa.layout" model.

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

pavankumarreddyr
Registered: Dec 8 2008
Posts: 18
Now i am able to fulfill my requirement.

I am facing one more issue at this point, problem is : In my PDF i am using dot operator as a part of field name.

Example: person.firstName, postion.title .....

so when i am trying to set focus for that field, or while doing nullTest for the field i am getting run time error saying 'no property exists'

My Code:

case 1:
xfa.host.setFocus("person.firstName");

case2:
if( person.firstName.rawValue == null )

How do i resolve this?

R pavan kumar reddy

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Do not use a dot in a field name. The dot has special meaning in pretty much any form technology, so it is an extreemly bad practice. Especially in a LiveCycle form. I'll repeat, Don't Do it.

If you need to group fields together then place them in a subform named "persion".

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

pavankumarreddyr
Registered: Dec 8 2008
Posts: 18
Thanks Thomp,

Now i replaced dot by underscore and script is working fine.

If dot convention is not supported in scripting why can't we restrict the user in entering dot in the name of the acro field while designing itself which is already happening for some of the characters say '[' - Live cyle designer won't allow user to enter '[' or ']' in the name of any acro field.

I got a requirement like i need to get focus to a required field when ever user misses to enter that.

When i say a field as required while designing acroform using LiveCycle Designer it adds following script to the xml:

above code throws a message whenever that particular field is left empty, but it won't get focus to that particular field.

I have done that using following script:

if(TextField_Name.rawValue == null)
{
TextField_Name.fillColor = "252,100,100";
xfa.host.setFocus("TextField_Name");
xfa.host.getFocus();
}

Above code will be difficult to maintain in case if i have more required fields, is there any generic way that i can handle about code. I mean will i be able to find all the required fields in a Acroform and iterate through that.


Suppose i have 120 fields and 10 fields are required in that - can i be able to differentiate these fields from the rest so that, i can iterate through these 10 fields and run above code.


Thanks in advance

R pavan kumar reddy

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, in XFA layout model there is a fuction called "pageContent", which when set up properly will return a list of all the fields on a page. A script can then iterate through the fields looking for any with the "mandatory" property set to "error", you could also look for the null test.

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

Alison
Registered: May 13 2008
Posts: 4
I understand how to validate dates and numbers to keep the focus in the field, but how would you do it for a phone number using the Validation Pattern?