Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Numeric Field Validation Message

Avatar

Former Community Member
I've created a benefits enrollment form with a numeric field that allows an entry between $50 and $10,000 or the field can remain blank.



Researching the forum entries provided me with this script to validate the amount entered and if the incorrect amount is entered, the field will not accept the invalid entry and reverts to a blank.



50 <= this.rawValue && this.rawValue <=10000

if ((this.rawValue <50)||(this.rawValue >10000))

{this.rawValue=null;}



My question is how to provide a message letting the user know the reason their entry hasn't been accepted?



At one time,I had an error message that worked however the invalid entry remained; another effort resulted in the error message displaying as soon as the form was opened.



I've added a tool tip, which displays OK and I've added Validation Script and Error Patterns on the Object/Value tab but neither of those ever show up.



Thanks for your help and please make your replies very simple to follow - I'm just getting started with these forms.
3 Replies

Avatar

Former Community Member
Hi Jane,

You can give a message with

if(this.rawValue < 50 || this.rawValue > 10000){

xfa.host.messageBox("Your value must be between 50 and 10000");

}



Asiye

asiyegunaydin@kgc.com.tr

Avatar

Former Community Member
Thank you for your reply. I appended your text to what I already have and it does work when an invalid number is entered however, the message is also displayed as soon as the form is opened. This is what I tried first as a validate event:



F.P1.Elections.HCRA.HCRAAmount::validate - (JavaScript, client)



50 <= this.rawValue && this.rawValue <=10000

if ((this.rawValue <50)||(this.rawValue >10000))

{this.rawValue=null;}

if(this.rawValue < 50 || this.rawValue > 10000)

{xfa.host.messageBox("Your value must be between 50 and 10000");}



It seems that when the form is opened, it sees the field is blank, recognizes it as being <50, thereby prompting the message to be displayed. Is that just the way it works or can the message be displayed only if the incorrect amount is entered?



I also tried using your text as a mouseUp event. It then gave the message only if I clicked in the field. It doesn't display if I tab to the field, and then I'm back to the same problem of the incorrect amount not being accepted and no explanation given. However, at this point, the user would be forced to return to the field, click in it and would then get your message.



I believe that will work for this form (along with a basic Tool Tip). I'm very new with the scripting portion of creating forms so if there's a less clumsy way to get the message across, I'd appreciate any other suggestions. Otherwise, thank you again for your help.

Avatar

Former Community Member
Hi Jane,

You hae to write my script on the exit event of the field,, which means when user writes a number to that area and focus to another field.



So use only my script on exit event:

if(this.rawValue < 50 || this.rawValue > 10000) {

xfa.host.messageBox("Your value must be between 50 and 10000");

}



If you want to use validate event you have to return true or false looking at your condition. And the validation error message that you will define in designer will be shown when you return false. This validation script will be as:

if(this.rawValue != null){

if(this.rawValue < 50 || this.rawValue > 10000) {

return false;

}

else{

return true;

}

}



Hope helps, otherwise you can send me email your form.



Asiye