Expand my Community achievements bar.

How to reset the field after validation fails?

Avatar

Former Community Member

Hi

I have a date field which should be lesser than current date. I have used validation code in the validate event which returns either true or false and based on that error message gets displayed, which is all working fine.

Now if the validation fails, I want to reset the field which is not happenning in my case.

Pls. help.

Thanks

Abhiram

3 Replies

Avatar

Level 10

Hi,

You could include a line as part of the validation script:

this.rawValue = null; 

So that if validation fails, the message will display and then the field will be cleared.

Hope that works,

Niall

Avatar

Former Community Member

By doing so, the field is getting cleared but the message is not displaying.

Suppose lets take a case of email validation.

I have used the following code in the validate event

var

r = new RegExp();

r.compile("^[a-z0-9_\\-\\.]+\\@[a-z0-9_\\-\\.]+\\.[a-z]{2,3}$"

,"i");

var

result = r.test(this.rawValue);

if

(result == true)

{

true;

}

else

{

false;

}

In this code if i use this.rawValue=null after or before "false" ,error message is not getting displayed.

Thanks

Abhiram

PS: Validation part is working absolutely fine.

Avatar

Level 10

Hi,

I think the issue is that the value of the selection is not complete when you are validating, try the exit event. Also try resetting the date:

xfa.host.resetData("xfa.form.form1.page1.DateTimeField"); 

Hope that helps,

Niall