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.

Validation Pattern Message

Avatar

Former Community Member
I want to script a Validation Error Message for a field that, on initialize, is in read-only mode. In Designer, when Type = "Read Only" the Validation Pattern and Validation Pattern Message are disabled. I can add script to define the pattern:



Myfield.validate.picture = "text{99999-9999}|text{99999}";



and trigger the validation:



Myfield.validate.formatTest = "error";



but how can I script the error message that the user sees? Doing the above generates a generic message "Myfield validation failed" but I would like the user to see a more description message, for example "Please enter a 5 digit or 5+4 digit zip code in the format 12345 or 12345-6789".



It seems silly that I add this field property at design time for a field that is NOT read-only, but not for one that toggles on/off from read-only to enabled. Any suggestions?
1 Reply

Avatar

Level 9
Hi



You can use the following:



tfPostalCode.validate.picture.value = "9999";

tfPostalCode.validate.message.formatTest.value = "An Australian Post Code must be a four digit number!";



Howard