Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

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

Avatar

Level 4

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?

1 Accepted Solution

Avatar

Correct answer by
Level 4

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

View solution in original post

4 Replies

Avatar

Correct answer by
Level 4

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

Avatar

Level 6
my component already has some clientlib and to that i added my new clientlib category, but its not getting picked up. do i have to call it somewhere?

Avatar

Level 4

@Shaheena_Sheikh The problem which I was actually facing was that, clientlib containing jquery was loading after this script hence without jquery all $ functions were not working. By main category I meant the clientlib category were jquery is kept. You can check the sequence of scripts/clientlibs loaded in the <head> tag of the page where you are getting the error. Regarding second comment, If you have created separate clientlib with separate category and the scripts are not getting added then you should probably check if your category is added in footlibs.html of your project.