Expand my Community achievements bar.

How to evaluate a value against a validation pattern in a script

Avatar

Level 2

I'm asking the filler to provide latitude of a location in degrees, minutes and seconds (2 digits each) in a text field. I have set the pattern values in the field's object palette so that if the latitude isn't provided in a 6-digit format an error message will be displayed instructing the filler accordingly.

The pattern is set as text{99'°'99'’'99'”'} so that the displayed value will be 99°99'99".

This is all fine and works great. Of course though, the filler can bypass the error message and leave an incomplete value in the field so I need to ensure they leave a 6-digit number in the field, or they leave the field blank, before exiting the field. So I would like to use coding in the field's exit event to keep the focus on the field until that happens (which I have done for other more straightforward validation).

It seems that a good way to do that would be to capture the result of the validation (like a true/false type of result) and use it in the exit event coding. Is this possible? Does the validation generate a result that can be captured?

If not possible this way, any suggestion in how to evaluate the value provided so that it is 6 digits?

Thanks

6 Replies

Avatar

Level 10

Hi,

You could check the length of the input in the exit event and then take appropriate action.

JavaScript in the exit event of the latitude field:

if (this.rawValue.length !== 6)

{

     this.rawValue = null; // clear the field

     xfa.host.messageBox("You have provided an incorrect latitude. \n\nPlease enter 6 digits", "Latitude error", 3, 0);

}

Maybe you should also consider placing the data pattern in a static text beneath the latitude field, in small font and a grey colour.

Hope that helps,

Niall

Avatar

Level 2

Thanks Niall, this got me going in the right direction. I also needed to test each character to ensure they were integer and have figured out a way of doing that.

Marc

Avatar

Level 10

Hi Marc,

I would strongly recommend using a numeric field for the input. This will automatically deal with the integer inputs.

Is there a reason that you are using a textfield?

Niall

Avatar

Level 2

I had tried using a numeric field, but I wasn't able to have the field behave the way I wanted it to. Because the desired display pattern is ##°##’##” where # would be integers, I used num{99'°'99'’'99'”'} as the Display, Edit, and Validation pattern type on the field's object tabs (I also tried num{zz'°'zz'’'zz'”'}).

I had two issues that made me use a text field instead:

- able to input alpha characters: as soon as I'm using a pattern on the Edit tab, I'm able to input alpha characters. Although it won't keep any input containing alpha characters, it still allows me to input them which I thought a numeric field would disallow no matter what. So to avoid confusion on the filler's side, my option would have been to not use a pattern on the Edit tab which effectively disallowed any non-numeric characters to be inputted in the first place. So this issue would have been handled.

- validation error message: but the main issue was that I wasn't able to have a validation error message popup when inputting less than a 6-integer value. I haven't found a pattern symbol that would allow me to exactly require a 6-integer value where any other input would trigger the validation error message. Is there one?

So if there is no such pattern symbol (or maybe I'm not doing this right in the first place), all I can think of to do what I'm trying to do is to use the text field with the same pattern above (as text{} of course). The validation error is triggered anytime something other than a 6-integer value is inputted. For all non-6-integer value, I use the Exit event to ensure the filler can't get out of the field until a 6-integer value is inputted or the filler deletes the value entirely.

I appreciate your continued help with this.

Marc

Avatar

Level 10

Hi Marc,

Try this out and see does that help: http://assure.ly/omkBWu.

Good luck,

Niall

Avatar

Level 2

Very helpful Niall. I went with the numeric field approach. All works great.

Thanks!!

Marc