I've created a custom metadata-schema which has some text fields, dropdowns and tag pickers. For one of the text fields, I want to apply a regex that will be validating the input which should be a string - 7 characters max, can only be letters and numbers (no characters), and no spaces. I've mapped the field to property ./jcr:content/metadata/shortcut-key
Accordingly I've created a clientlib under apps with category : dam.gui.coral.metadataeditor

The hierarchy is as follows :
\-- metadata-validation (cq:ClientLibraryFolder)
\-- js.txt (nt:file)
\-- js (nt:folder)
\-- metadataValidation.js (nt:file)
The JS file has the following code :
(function($) {
$(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
selector: '[name="./jcr:content/metadata/shortcut-key"]',
validate: function(element) {
const wrapper = $(element).parents().eq(1);
// Apply only if schema is custom-schema
if(!wrapper
|| !wrapper.attr('data-path')
|| !wrapper.attr('data-path').startsWith('/conf/global/settings/dam/adminui-extension/metadataschema/custom-schema')) return;
const validationRegex = /^[A-Za-z0-9]{1,7}$/;
if (!validationRegex.test(element.value)) {
return Granite.I18n.get('String — 7 characters max, can only be letters and numbers (no special characters, no spaces)');
}
}
});
})(Granite.$);
Now the issue is although the validations are working - it allows to save the metadata schema along with validation errors.


As per https://medium.com/@theopendle/aem-custom-metadata-forms-for-assets-8c6597205f9d - it should throw the pop-up text and not allow to save the form.
Can someone let me know what is the issue over here? And how to prohibit the form from getting submitted when there are validation errors.