Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

converting validation pattern to script syntax and running check

Dave_Erho
Level 3
Level 3

Hi,

I am working on a form where I want to have users enter info in a field called "ID Number" according to a strict pattern. In this case AAA9999-A.

However, if the pattern is not met, I want the field to reset and the focus to be put back into the field. In other words, I don't want the user to move on in the form unless they have entered the value in the field according to the pattern.

It looks like using a validation pattern does not have the capability of clearing the field input and setting the focus. So I wanted to know the best way to do that with script. The only thing is, I don't know how to convert the validation pattern into script syntax and then check for it.

Any ideas?

1 Reply
_Bruce_Robertson
Level 10
Level 10

Hi Dave,

If you have a validation pattern of AAA9999-A then the I expect you are wanting the user to type in something like ABC1234A (that is without the hyphen), if you set the display pattern to the same then the hyphen will be added in for them.  If this is the case then the rawValue and the formattedValue will only be different when the value is invalid.  So you could try the following JavaScript in the exit event.

 

if (TextField1.rawValue === TextField1.formattedValue)

{

   //xfa.host.resetData(this.somExpression);

   xfa.host.setFocus(this);

}

 

I know there are some cases were we need this but controlling the order the user completes the form is generally considered bad usability, which is why you don't get this behaviour by default.

Hope this helps

Bruce