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.

JavaScript validation message not run

Avatar

Former Community Member
In my GPA numeric type field, I have the following script associated with the GPA field:



----- F.P2.HighSchool_GPA::validate - (JavaScript, client) ----------



0 <= this.rawValue && this.rawValue => 4.00



I then checked the Validation Script Message error check box. However, when I typed in 5.5 and use the keyboard tab key to the next field, I do not receive any pop up error. It is set to Run At client and uses JavaScript language.
4 Replies

Avatar

Former Community Member
Try this script instead:



if (this.rawValue != null) {

if (this.rawValue >= 0 && this.rawValue <= 4) {

true

} else {

false;

}

}



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Thank you so much! That works! However, one more question. Is there a way to have the cursor come back and highlight the field that generates the pop up error message? Currently after I click OK on the pop up error window, the cursor either focuses on the next field or not found at all on the form.

Avatar

Former Community Member
Not the way you're doing it. But you could uncheck the validation script error message choice in the UI and use a script like this:



if (this.rawValue != null) {

if (!(this.rawValue >= 0 && this.rawValue <= 4)) {

xfa.host.messageBox("Error Message");

xfa.host.setFocus(this.somExpression);

}

}



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Again, the code you provide works and I can live with it now. Thanks! But just curious, why is it not working when I use the enter key on the keyboard instead of the tab or the mouse? Currntly if I use the tab on the keyboard or the mouse to move to the next field then after the popup error window the focuse will come back to the field that generates the error, but not if I use the enter key on the keyboard.