Expand my Community achievements bar.

Have a field with validation, will get error popup, but will still accept input

Avatar

Level 1

Hi,

I Have a field with validation, if input is incorrect I do get an error message, but the form will still accept the incorrect input.

How can I force the user to correct the input before leaving the field?

Here are the validation conditions:

this.rawValue>=1.35 && this.rawValue<=1.47;

I am a VERY new user with no programming experience, so please keep it in layman's terms.

Thanks for your help,

Bryan

3 Replies

Avatar

Level 10

Place the below code in the Validate event..

if(this.rawValue>=1.35 && this.rawValue<=1.47){
this.tst = true;
this.tst || Boolean(this.execEvent("exit"));
}
else
this.tst = false;

And then place the below code in the Exit event..

if

(this.rawValue != null && this.rawValue != ""){

     if(!(this.tst)){

          //if Validate event does not get executed, this.tst value is coming as undefined, then force to execute the validate event

          if(this.tst == undefined)

               this.execEvent("validate");

          else

          xfa.host.setFocus(this.somExpression);

     }

}

Thanks

Srini

Avatar

Level 1

Thank you Srini for the help.

It does work, however, if you click on the adjoining cell a number of times it will eventually accept the incorrect data.

Shouldn't it refuse to take the data altogether, or did I not copy and paste the data correctly?

Thanks,

Bryan

Avatar

Level 10

Try this code in the Validate event.

var blnValidationFailed = false;

if(this.rawValue>=1.35 && this.rawValue<=1.47){
blnValidationFailed = true;
}


if(blnValidationFailed == false)
     this.tst = false;
else
     this.tst = true;
     this.tst || Boolean(this.execEvent("exit"));

Thanks

Srini