Hi all,
I want to validate a text field (string, named "Kontierungselement") based on the length. So allowed are 10, 8 or 7 char. I limited the field to 10 char. But for every other input there should be an error message. I put the error message in the validate script message of the object and tried it with this code inside the validate event.
But my problem is that the length (currentLength) is not working - I all the time see 0 instead of the correct value, any ideas?
FormServiceRequestConfirmation.mstPageSet1.mstPage1.frmTitle.Kontierungselement::validate - (JavaScript, client)
console.show();
var currentLength = xfa.event.newText.length;
console.println(currentLength);
var kontierungselement = FormServiceRequestConfirmation.mstPageSet1.mstPage1.frmTitle.Kontierungselement;
console.println(kontierungselement.length);
if(currentLength != 10 && currentLength != 8 && currentLength != 7){
result = false;
}
Thanks a lot!
Deborah
Solved! Go to Solution.
Views
Replies
Total Likes
Hi there,
if you are using xfa.event.newText, it should be within the "enter" event.
Any other event will need to use this.rawValue instead.
I hope this will help
Views
Replies
Total Likes
Hi there,
if you are using xfa.event.newText, it should be within the "enter" event.
Any other event will need to use this.rawValue instead.
I hope this will help
Views
Replies
Total Likes
Hi @Magnus069,
if I use this.rawValue.length and still the validate event I got the following error:
TypeError: this.rawValue is null
5:XFA:FormServiceRequestConfirmation[0]:mstPageSet1[0]:mstPage1[0]:frmTitle[0]:Kontierungselement[0]:validate
What can I do?
Views
Replies
Total Likes
Views
Replies
Total Likes
The rawValue is only updated when you exit a field.
You can use a script with regular expression in the exit event to test against the rawValue.
if (this.rawValue.match(/^(\D{7,8}|\D{10})$/) === null) {
xfa.host.messageBox("Invalid value entered.");
}
Views
Likes
Replies