Expand my Community achievements bar.

Validation error

Avatar

Level 2

I am having a problem with some javascript.

I have created a date field that should be populated if another field is filled in.

In the filled in field, I have the code:

if

(this.rawValue != null|| this.rawValue > 0)

{

xfa.form.form1.Translator.TranslatorDate.rawValue

=util.printd("dd/mm/yyyy",new Date());

}

the date field also has a validation pattern of (in case someone manually enters a date)

date{DD/MM/YYYY}

The code works but before the date field is filled in a message box pops up with:

the validation message:

"Please enter date as dd/mm/yyyy"

How do I get around the pop up message.  If I remove the validation pattern it works but the end user is not prompted if they enter the date in the wrong format.

Thank you,

4 Replies

Avatar

Former Community Member

i put

.endDate.validate.formatTest = "disabled";

.endDate.validate.scriptTest = "disabled";

in the "initialize" event......

Avatar

Level 2

Thanks but this works the same as removing the validation pattern.  If the client changes the date and does not use the proper format he is not prompted with the validation script.

I tried disabling it in the initialize and enabling it in the change event but the validation script still  does not prompt the user if the data format is incorrect.

In the date field initialize

this.rawValue

= util.printd("dd/mm/yyyy", new Date());

this.validate.formatTest

= "disabled";

this.validate.scriptTest

= "disabled";

In the change event of the field:

this.validate.formatTest

= "enabled";

this.validate.scriptTest

= "enabled";

Avatar

Level 6

Did anyone found a solution to this problem? To disable and enable validation doent seems to be the best approach. If one clicks on a Print button for instance, the user will get the error.

So, the problem is this: with a date filed with a validation pattern, any value we set dynamically (using javascript code) will throws a validation error.

thank you

Avatar

Level 2

Just to close out on this thread...

I found the best way to deal with this issue is to leave the calendar drop down but add a pattern to the change event of the field.


This will let the client select the date or validate a date that has been manually entered.

Hope this helps,