Saturday 7 October 2017

How to restrict user while creating a AEM/CQ page in upper case?

There are use case in which client need to prevent author from creating cq page name in UPPER CASE.
Perform the following step to allow author to create page only in lower case or numbers.
  1. Copy Page.Actions.js from /libs/cq/ui/widgets/source/widgets/wcm/Page.Actions.js to /apps//cq/ui/widgets/source/widgets/wcm/Page.Actions.js
  2. search te beforesubmit function – dialog.on(“beforesubmit”, function()
  3. Add below code under beforesubmit function
var label = document.getElementsByName(“label”);
var labelValue = “”;
for(var labelCount = 0; labelCount < 1000; labelCount++) {
if(label[labelCount] != null) {
//alert(label[labelCount].value);
labelValue = label[labelCount].value;
}
}
if(labelValue.length > 0 && !/^[a-z0-9\-]+$/.test(labelValue)) {
CQ.Ext.Msg.show({
title:CQ.I18n.getMessage(‘Move Page’),
msg: CQ.I18n.getMessage(‘”Name” field should have only “-“,lower case alphabets or numbers.’),
buttons: CQ.Ext.Msg.OK,
icon: CQ.Ext.Msg.ERROR
});
//alert(“\”Name\” field should have only \”-\”, 0 to 9 and lower case alphabets.”);
return false;
}
Note :- Do not edit under libs folder

No comments:

Post a Comment