Last active
March 3, 2022 11:47
-
-
Save theopendle/6c4469dff5d84211fe6454034baf10ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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