Need to validate the text Field Inside Dialog(Need the Proper Way how to call the JS into component) | Community
Skip to main content
Level 2
March 22, 2024
Solved

Need to validate the text Field Inside Dialog(Need the Proper Way how to call the JS into component)

  • March 22, 2024
  • 2 replies
  • 1599 views

slightly code

<sly data-sly-use.clientlib ="/libs/granite/sightly/templates/clientlib.html">
<sly data-sly-call="${clientlib.js @ categories='videoupload'}"/>
</sly>



js code 


(function($ , Coral) {
"use strict";
console.log("------------Clientlibs Loaded-----------");

var registry = $(window).adaptTo("foundation-registry");

registry.register("foundation.validation.validator", {
selector : "[data-validation = youtubeurl]",
validate : function(element) {
let el = $(element);
let url = el.val();
var youtubeRegex = /^(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+/;
if (!youtubeRegex.test(url)) {
return "Enter the Youtube Url";
}
}
});

})(jQuery, Coral);


folder structure 


Response 

  - not getting my error message



This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

HI @sanjaykumardas 
The way you included clientlibs will not be executing for dialog.

 

Please follow the below article : https://aemhints.com/2020/11/02/validating-dialog-value/ 

2 replies

anupampat
Community Advisor
Community Advisor
March 22, 2024

Hi @sanjaykumardas ,

 

Can you call your clientlib on the dialog and check if the JS is called, also check if your regex is correct , validate with https://regex101.com/?

 

 

 

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="nt:unstructured" jcr:title="Video Upload" sling:resourceType="cq/gui/components/authoring/dialog" extraClientlibs="[videoupload]"> <content jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"> ....

 

 

 
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
March 22, 2024

HI @sanjaykumardas 
The way you included clientlibs will not be executing for dialog.

 

Please follow the below article : https://aemhints.com/2020/11/02/validating-dialog-value/ 

Arun Patidar
Level 2
March 22, 2024

Hi @arunpatidar   , thank you for the response but when i am trying with below link still not working can you help on this

 https://aemhints.com/2020/11/02/validating-dialog-value/  

i am adding my package here you get it from drive - https://drive.google.com/file/d/1OqW4Xzr2xil53MHr8e5MjyfRpyYbN4XH/view?usp=sharing