Expand my Community achievements bar.

SOLVED

Set focus on phone number field when validations fails

Avatar

Level 5

Hello,

I have a text field set up as a phone number field, with the following in the change event to accept numbers only:


if(xfa.event.newText.match(/[^0-9]/)){


xfa.event.change = "";


}


In the Pattern validation, I have this mask on all tabs (Display, Edit, Validation and Data):

text{'('999')' 999-9999}

I want the user to be able to just enter numbers and have the parentheses and dash added automatically ["(123)-456-7890"].


How do I get the focus to stay on this field when it fails validation? (e.g., insufficient or too many digits).  I have looked into validationState but couldn't figure out how to use it (I'm a noob javascripter).

Thanks for any help.

1 Accepted Solution

Avatar

Correct answer by
Level 7

in the exit event of your field:


if (this.rawValue.length !=9) xfa.host.setFocus(this);


View solution in original post

3 Replies

Avatar

Correct answer by
Level 7

in the exit event of your field:


if (this.rawValue.length !=9) xfa.host.setFocus(this);


Avatar

Level 5

That worked, thanks!  The only change I made was to insert "10" instead of "9" for the phone digits.


if (this.rawValue.length != 10) xfa.host.setFocus(this);


Avatar

Level 7

Yeah, I'll learn how to count one day...