Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

I have to validate a numeric field in LC so that it is a 1, 2 or 3.

Avatar

Former Community Member

Is there a pattern I can use or do I have to create a custom script? If I

use this:

this.rawValue

>= 0 && this.rawValue <= 3;

if

(this.rawValue < 1) {

this.rawValue

= 0;

}

if

(this.rawValue > 3) {

this.rawValue

= 0;

}

I get a validation error for every field (70 of them) when the form opens and there is a message box on each filed. I tried a default value of 0 for each field but still get the message.

The field can be null, 0 (when turned off) ot 1,2 or 3.

1 Accepted Solution

Avatar

Correct answer by
Level 10

and operator in Java Script is "&&" and in FormCalc it is "and"

or operator in Java Script is "||" (double pipe) and in FormCalc it is "or"..

Otherway way of doing your code is:

//Execute the below statements only if the value is not null

if(this.rawValue != null){

     if(this.rawValue <1) {
          this.rawValue= null;
     }

     if(this.rawValue > 3) {
          this.rawValue= null;
     }

}

Thanks

Srini

View solution in original post

7 Replies

Avatar

Level 10

When I change the value to null, the validation messages are not displaying..

if(this.rawValue <1) {
  this.rawValue= null;
}

if(this.rawValue > 3) {
  this.rawValue= null;
}

Will this help?

Patterns only check for whether the user is entering the input in a particular format. You may not be able to place script as part of pattern.

Make this script as part of a Scrip Object and call the script in all of the fields where ever you need. That way script maintenance will be easier.

Thanks
Srini

Avatar

Former Community Member

While it works, I do not get any validation message at all.

I'm not familiar with Java. Is there a way to do a message box?

Avatar

Level 10

If you are looking for how to do a messageBox, here it is..

xfa.host.messageBox("Text to be displayed", "Caption of the Message box",<Integer representing the icon to display in the dialog box>, <Integer representing the buttons to display>);

If you need more on what integers you can use, please goto help in your LiveCycle Designer and type MessageBox in the Index.

Hope this helps.

Thanks

Srini

Avatar

Former Community Member

Ok, one last question, how do you represent an or condition in an if statement?

I know it's basic.

I want the message to come up if the value is <1 or greater than 3 but not when it's null.

Avatar

Correct answer by
Level 10

and operator in Java Script is "&&" and in FormCalc it is "and"

or operator in Java Script is "||" (double pipe) and in FormCalc it is "or"..

Otherway way of doing your code is:

//Execute the below statements only if the value is not null

if(this.rawValue != null){

     if(this.rawValue <1) {
          this.rawValue= null;
     }

     if(this.rawValue > 3) {
          this.rawValue= null;
     }

}

Thanks

Srini