Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Date validation

Avatar

Former Community Member
Hi,



I am trying to validate a date format for a PDF form. The validation pattern is MM/DD/YYYY, and the Validation Pattern Message I set up is simply Invalid Date format. When the user enters an invalid date and hits tab, the error message is displaying properly, but the cursor still moves on to the next field. Is there a way to incorporate a script along with this validation pattern so the focus will keep going back into the date field until it has been validated?



Thanks in advance.
4 Replies

Avatar

Former Community Member
The following code will set the focus of the cursor.



xfa.host.setFocus(focusObject);



focusObject being a SOM expression representing the field, such as:

xfa.form.DateForm.MyDate



As for how to trigger this if the validation fails, I'm not too sure as to how you could do this. There is a way to evaluate the validation to see if it passed or failed, but I'm not sure how.

Avatar

Former Community Member
Dear Chad, I have exactly the same problem, did you get it fixed?

Please let me know your logic and codes! Thanks a lot

Avatar

Former Community Member
A word of warning. I tried using the xfa.host.setFocus() to create this behavior. This can potentially leave you in a loop. here is the scenario. You ahve two fields which contain validations and use the xfa.host.setFocus to bring focus back to the field. If you type in data into a field and hit tab it moves to the next field. If you are quick enough you can sometimes enter data into the next field before the validation of the first is triggered. If you enter bad dat in the first and second field the setFocus will cause a loop.

Avatar

Former Community Member
Dear Cherles, Would you please show me how you use setFocus in a validation rule? If you just copy and past some codes for me.

Thanks