Hi All.
I have TextField with pattern text{AA12345A} to display and the same to validation. If user will enter data with wrong format, for instance, ABA4565B and validation will come up how to clear intered value and keep focus to the same field?
Thanks.
Views
Replies
Total Likes
The pattern text{AA12345A} is not valid itself, it should be text{AA99999A}
Views
Replies
Total Likes
I tried removing all the pattern validations on the field and added this below code in the validate event of the text field and it works..
var strCode;
var f = /^([A-Z]{2}[1-9]{5}[A-Z])$/;
if(this.rawValue != null && String(this.rawValue) != "") {
strCode = String(this.rawValue);
if (f.test(strCode) == false) {
xfa.host.messageBox("Invalid pattern!");
xfa.host.resetData();
xfa.host.setFocus(this);
}
}
xfa.host.setFocus(this);
Views
Replies
Total Likes
Hi rashmi. Thanks for replay.
I remove pattern and place your code to validate event like you suggest to do. But unfortunately, when I entered correct or not correct value in both cases I got the error message. How it fix?
Thanks.
Views
Replies
Total Likes
Yes thats right just checked it again..
Is there smething else you are expecting?
Have I missed something?
Views
Replies
Total Likes
But how fix problem? Thanks.
Views
Replies
Total Likes
Hi,
use this script in the exit event of your field.
if (!this.rawValue.match(/^[a-zA-Z]{2}[0-9]{5}[a-zA-Z]{1}$/g)) {
xfa.host.messageBox("Enter correct format 'AA99999A'.", "Wrong Entry", 0,0);
this.rawValue = "";
xfa.host.setFocus(this.somExpression);
}
Views
Replies
Total Likes
HI radzmar. Thanks for replay.
I used your code in EXIT event like you suggested. In preview PDF mode it works without any problem. But when I saved the file and open in Acrobat Pro I met problem. If I type correct value format everything works fine but when I type wrong value I got error message accordingly by code and after click OK button the JavaScript Debugger window pop up with such message:
this.rawValue is null
7:XFA:form1[0]:#subform[0]:txtCIN[0]:exit
TypeError: this.rawValue is null
7:XFA:form1[0]:#subform[0]:txtCIN[0]:exit
How to fix that problem?
Thanks.
Views
Replies
Total Likes
To avoit that exception we need to add one more if-expression to check for null-values.
if (!this.isNull) {
if (!this.rawValue.match(/^[a-zA-Z]{2}[0-9]{5}[a-zA-Z]{1}$/g)) {
xfa.host.messageBox("Enter correct format 'AA99999A'.", "Wrong Entry", 0,0);
this.rawValue = "";
xfa.host.setFocus(this.somExpression);
}
}
Views
Replies
Total Likes
Thanks a lot. Just two more questions. For what purpose do you use / g in string format? And if I will need different type format. Where do I read about it?
One more time thanks for help.
Views
Replies
Total Likes
Views
Likes
Replies