Uncaught TypeError: $(...).adaptTo is not a function

Avatar

Avatar

pillaivinit

Avatar

pillaivinit

pillaivinit

28-12-2020

I created a validation for a dialog in AEM 6.3

Following is the code of my validation.js

(function($, window, document) {
var registry = $(window).adaptTo("foundation-registry");

registry.register("foundation.validation.validator", {

selector: "[data-validation=txt-validate]",
validate: function(el) {
var element = $(el);
console.log(element);
var pattern = element.data('pattern');
var value = element.val();
if (value.length == 0) {
console.log('No validation pattern was mentioned.')
return "Please enter text";
} else {

patterns = {

phone: {
regex: /(\([0-9]{3}\))([0-9]{3})-([0-9]{4})/ ,
format: '(000)000-000',
},

email: {
regex: /((([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?/,
format: 'email',
},

}

/*
* Test pattern if set. Pattern can be a preset regex pattern name or
* a regular expression such as "^\\d+$".
*/
if (pattern) {
if (patterns[pattern]) {
error = !patterns[pattern].regex.test(value);
if (error) {
return "The field must match the pattern of " + patterns[pattern].format;
}
} else {
error = !(new RegExp(pattern)).test(value);
if (error) {
return "The field must match the pattern of " + pattern;
}
}
}
}
}
});
})
($, window, document);

 I'm getting the following error and the validation is not working.

error: $(...).adaptTo is not a function

 

the content.xml of my clientlibs folder where validation.js is present is

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
categories="[cq.authoring.dialog, my.category]"/>

 

Why adaptTo is not a function?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

pillaivinit

Avatar

pillaivinit

pillaivinit

28-12-2020

Added the category as the main category and it worked. not a good answer but works.

Answers (0)