Skip to content

Instantly share code, notes, and snippets.

@theopendle
Last active March 3, 2022 11:47
Show Gist options
  • Save theopendle/6c4469dff5d84211fe6454034baf10ce to your computer and use it in GitHub Desktop.
Save theopendle/6c4469dff5d84211fe6454034baf10ce to your computer and use it in GitHub Desktop.
(function($) {
$(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
selector: '[name="./jcr:content/metadata/dc:title"]',
validate: function(element) {
const wrapper = $(element).parents().eq(1);
// Apply only if schema is wknd-default
if(!wrapper
|| !wrapper.attr('data-path')
|| !wrapper.attr('data-path').startsWith('/conf/global/settings/dam/adminui-extension/metadataschema/wknd-default')) return;
// Min 3 characters, first being capital letter, others being alphabetical characters
const validationRegex = /^[A-Z][a-zA-Z]{2,}$/;
if (!validationRegex.test(element.value)) {
return Granite.I18n.get('This field must be at least 3 characters long, begin with a capital letter and contain only alphabetic characters');
}
}
});
})(Granite.$);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment