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

Data validation in Livecycle

Boon
Registered: May 5 2010
Posts: 66
Answered

Hello,

I was trying to create a validation rule in Livecycle but did not find any success.

I looked at the sample "Grant Application.pdf". And it seems that it did not work as well.

In the text field for zipcode, there is a validation rule setup. The setup is to allow 5 digit zipcodes and all must be numeric. When I preview the form and put in 'invalid' zipcode (e.g. 5348A), there is a message warning. But, when I click OK on the message, I can leave the zipcode text field and fill in the data in other fields as normal. the the value in zipcode box shows 5348A.

What I would like the form to do is that it won't accept the invalid value and the form does not lose focus on the zipcode text field. the form must warns users until they input the correct value.

How can I do this?

thanks!
Boon

--SID--
Registered: May 4 2010
Posts: 31
You can make this a required field.
and when your validation fails, you can reset this field.

this way, whenever the validation fails, the field will go empty and without filling it the user will not be able to continue submission.

~~ S I D ~~

Boon
Registered: May 5 2010
Posts: 66
Yes, but how to reset the field?

When I worked in Acrobat PRO, I used this java script to do the job..

var cus= /^(\d{5}[A-Za-z\d]|0[N-n]\d{4}|[C-c]\d{4}[A-Za-z]|[C-c]\d{5}|\d{6})$/;


if (!cus.test(event.value))
{
event.rc = false;
app.alert("reenter please");
};


This code will not allow input data that fail the regexp. if it fails, the focus is still on that field.

How can I accomplish this in Livecycle?

thanks!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The "event.rc" and "event.value" properties are for the AcroForms model only. In liveCycle forms the validation script tests the "this.rawValue" property and the last value in the script is the result. The return value determines whether or not the "Validation" message is displayed

Try this by itself:

cust.test(this.rawValue);

However, if the script is going to clear the value and display it's own message the return values are not important.

For example

if((this.rawValue != null) && !cust.test(this.rawValue))
{
this.rawValue = "";
app.alert("reenter please");
xfa.host.setFocus(this.somExpression);
}

Testing for the null value is important to make sure the failure is not erroneously triggered.

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]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

Boon
Registered: May 5 2010
Posts: 66
Thomp,

Great! It works.

I am a newbie here and would like to ask you for more detail.

what is the different between rawValue and Value? I noticed that most of the time, I need to use rawValue. When will I need to use Value?

I don't understand what somExpression means.... but can I say that every time I want to set focus I can use this code -> xfa.host.setFocus(this.somExpression);thanks!
Boon
Boon
Registered: May 5 2010
Posts: 66
Thomp,

one more thing... Can we do this on the Validation Pattern under Object>Value pallatte?what is the Validation Pattern for?


thanks.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Don't ever use "value", it is a reference to the underlying XML structure of the form model. Everything in a LiveCycle form is an XML node, an attribute of a node, or a shortcut to a node. The XML path to any of these is called the Scripting Object Model, or SOM. The "somExpression" is a property of every node that gives the SOM path for that object. "this.somExpression" refers to the SOM path for the current object. If you want to set the focus to a different object/node, then you have to provide a different SOM path.

The validation patter on a field is for using the built-in validation. The format if this pattern is called a Picture Clause. Since you wanted functionality that is not provided by the built in validation you required a custom validation script that overrides the built-in functionality.

There are documents on www.adobe.com/devnet/acrobat that cover all these different things.

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]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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