Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

SetFocus on Exit problem

Avatar

Former Community Member
I'm using a script on the exit event to validate a text field as a date. When testing I can press the enter button and tab off the field with bad data in it. Does anyone know why this is happening?



Thanks,



Ken



Here's the script I'm using



var re = new RegExp(); // Create a new Regular Expression Object.

re.compile(/^\d{1,2}\/\d{1,2}\/\d{4}$/);// Set the reg exp



if ((re != null) && (re.test(this.rawValue) == false))

{

xfa.host.messageBox("Please enter a valid date (MM/DD/YYYY).","Invalid Date",0);

xfa.host.setFocus("StatementDate[0]");

}
5 Replies

Avatar

Former Community Member
Try giving the full path to the field you want to set the focus to, as in:



xfa.host.setFocus("formname[0].subformname[0].StatementDate[0]");



Regards,

Dave

Avatar

Former Community Member
Thanks for the info Dave. I tried that but it still seems to be giving me a problem. What's happening is if I put in bad data and hit tab it gives me the error message and when I hit enter or click the OK button it gives me focus back to the offending field. So far so good. The problem is if I have bad data in the field and press the enter key and then press the enter key again twice (instead of tab) the field loses focus and I can tab or mouse out with the bad data left in the field. It's strange... I guess most users won't try to break it, but it should work. I wonder if I should put the code in the enter event...



Thanks,



Ken

Avatar

Former Community Member
How about wiping the field before you reset the focus after the validate fails? I haven't tried this but it should be as simple as setting the raw value to "".



Regards,

Dave

Avatar

Level 6
In some cases, automatically clearing the field is a good option, but in other cases I would consider it "user abuse". If someone mistypes a credit card number, for example, they will want to go back and fix the typo rather than type in the whole thing again.



The way LiveCycle handles validations is to bark at the user as they exit the field, but allow the user to continue filling out the form. However, LiveCycle will prevent the user from submitting the form if there are validation errors. The user can still save and can still print. Often my clients want to prevent printing and saving unless the form is valid, but there's no simple way to do that. One option is to put a conspicuous marker on the form (DRAFT or WORK IN PROGRESS watermark on the master page, for example) that indicates that the form is incomplete. You can clear the watermark when the form is valid (i.e. xfa.form.execValidate() returns true).



Jared Langdon

http://www.jlangdon.ca

Avatar

Former Community Member
Thanks Dave and Jared. Yes. I agree. The user shouldn't have to retype a whole entry if there is just one character off. But there should also be a way to force validation of a field before the focus is lost. In our case though we, are uploading the form instead of submitting it (which I'd like to change) so there really isn't a way to validate it like I would want. It seems that everytime there's one solution to a problem another one crops up. For instance, I was able to use a Date field and control the way it's displayed etc in Designer, but I can't force the entry to be valid before tabbing off. So then I go to a script and I can't control the display output, but I can force the way the date is entered. But then I find there's still a way to get by the field by hitting enter a few times. It's frustrating! Well, I'm ranting... I'll try the 'Draft' watermark idea and see if I can get a submit button put on the form.



Thanks,



Ken