Skip to content

Commit 4848bd6

Browse files
AnurudraSci-build
authored andcommitted
FORMS-12822 : format should not be visible when no pattern is selected (#1196)
* FORMS-12822 : format should not be visible when no pattern is selected * FORMS-12822 : changes var to let as per ES6 in utils.js
1 parent 7f470d9 commit 4848bd6

File tree

2 files changed

+55
-36
lines changed

2 files changed

+55
-36
lines changed

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/af-commons/v1/clientlibs/editor/utils/utils.js

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
*/
3636
static checkAndDisplay(components) {
3737
return function(condition) {
38-
var elemArray = components instanceof Array ? components : [components];
38+
let elemArray = components instanceof Array ? components : [components];
3939
elemArray.forEach(function(elem) {
4040
if (condition()) {
4141
elem.show()
4242
} else {
4343
elem.hide()
44+
elem.hide()
4445
}
4546
});
4647
}
@@ -88,8 +89,8 @@
8889
* @returns {String} Value of the selected radio option
8990
*/
9091
static getSelectedRadioGroupOption(component) {
91-
var radioComp = component.find('[type="radio"]');
92-
for (var i = 0; i < radioComp.length; i++) {
92+
let radioComp = component.find('[type="radio"]');
93+
for (let i = 0; i < radioComp.length; i++) {
9394
if ($(radioComp[i]).prop("checked")) {
9495
return $(radioComp[i]).val();
9596
}
@@ -103,7 +104,7 @@
103104
*/
104105
static initializeEditDialog(editDialogClass) {
105106
return function() {
106-
var args = Array.prototype.slice.call(arguments);
107+
let args = Array.prototype.slice.call(arguments);
107108
/**
108109
* Initialise the conditional display of the various elements of the dialog.
109110
*
@@ -130,23 +131,23 @@
130131
*/
131132
static renderSubDialog(container) {
132133
return function(dialogPath, callback) {
133-
var args = Array.prototype.slice.call(arguments);
134-
var $container = $(container);
135-
var componentPath = $container.data("componentpath");
136-
var isDialogRendered = false;
134+
let args = Array.prototype.slice.call(arguments);
135+
let $container = $(container);
136+
let componentPath = $container.data("componentpath");
137+
let isDialogRendered = false;
137138
if (componentPath && dialogPath) {
138139
$container.empty();
139-
var currentDialogPath = dialogPath + "/cq:dialog.html";
140+
let currentDialogPath = dialogPath + "/cq:dialog.html";
140141
if (currentDialogPath.indexOf("/") !== 0) {
141142
currentDialogPath = "/mnt/overlay/" + currentDialogPath;
142143
}
143-
var actionPath = currentDialogPath + componentPath;
144-
var subDialogResponse = CQ.shared.HTTP.get(actionPath);
144+
let actionPath = currentDialogPath + componentPath;
145+
let subDialogResponse = CQ.shared.HTTP.get(actionPath);
145146
if (CQ.shared.HTTP.isOk(subDialogResponse)) {
146-
var parser = $(window).adaptTo("foundation-util-htmlparser"),
147+
let parser = $(window).adaptTo("foundation-util-htmlparser"),
147148
html = subDialogResponse.body;
148149
parser.parse(html, true).then(function (dialogHtml) {
149-
var $subDialogContent = $(dialogHtml).find('.cq-dialog-content');
150+
let $subDialogContent = $(dialogHtml).find('.cq-dialog-content');
150151
$subDialogContent.addClass("guide-dialog");
151152
if ($subDialogContent.length > 0) {
152153
isDialogRendered = true;
@@ -162,43 +163,44 @@
162163
}
163164

164165
static handlePatternDropDown(dialog, patternClass, formatClass) {
165-
var patternComponent = dialog.find(patternClass)[0];
166-
var formatComponent = dialog.find(formatClass)[0];
166+
let patternComponent = dialog.find(patternClass)[0];
167+
let formatComponent = dialog.find(formatClass)[0];
167168
_managePatternDynamicBehaviour();
168169
patternComponent.addEventListener("change", _managePatternDynamicBehaviour );
169170
function _managePatternDynamicBehaviour() {
170-
var displayPatternSelectedValue = patternComponent.selectedItem.innerHTML;
171-
var patternComponentOptionsNodeList=patternComponent.querySelectorAll('coral-select-item');
171+
// below the pattern was compared based on the name rather than the value ("No Pattern" instead of ####.####) which was creating issue in other languages therefore now it has changed to value.
172+
let displayPatternSelectedValue = patternComponent.selectedItem.value;
173+
let patternComponentOptionsNodeList=patternComponent.querySelectorAll('coral-select-item');
172174
if(patternComponentOptionsNodeList.length<=2 ){
173-
//there are 2 default options, "Select" and "custom".
175+
//there are 2 default options, "Select" and "custom".
174176
// For this dropdown to be visible it should have atleast one other option
175-
var patternComponentParentDiv=patternComponent.closest("div");
177+
let patternComponentParentDiv=patternComponent.closest("div");
176178
patternComponentParentDiv.setAttribute("hidden", true);
177179
}else {
178-
var displayFormatParentDiv=formatComponent.closest("div");
180+
let displayFormatParentDiv=formatComponent.closest("div");
179181
switch (displayPatternSelectedValue) {
180-
case "Select" :
181-
case "No Pattern" :
182+
case "" :
183+
case "#####################.###############" :
182184
displayFormatParentDiv.setAttribute("hidden", true);
183185
break;
184186
default :
185187
displayFormatParentDiv.removeAttribute("hidden");
186188
}
187189
}
188-
if(displayPatternSelectedValue!="Custom") {
190+
if(displayPatternSelectedValue!="custom") {
189191
formatComponent.value = patternComponent.value;
190192
}
191193
}
192194
}
193195

194196
static handlePatternFormat(dialog, patternClass, formatClass){
195197

196-
var patternComponent = dialog.find(patternClass)[0];
197-
var formatComponent = dialog.find(formatClass)[0];
198+
let patternComponent = dialog.find(patternClass)[0];
199+
let formatComponent = dialog.find(formatClass)[0];
198200
_manageFormatChange()
199201
formatComponent.addEventListener("change", _manageFormatChange );
200202
function _manageFormatChange(){
201-
var itemFound=false;
203+
let itemFound=false;
202204
if(formatComponent.value!=patternComponent.value){
203205
patternComponent.items.getAll().forEach(function (item) {
204206
if (item.value == formatComponent.value) {
@@ -223,10 +225,10 @@
223225
*/
224226
static registerDialogDataTypeValidators(defaultTypeSelector, enumSelector, getSelectedDataType) {
225227
return function (dialog) {
226-
var isBoolean = function(value) {
227-
var isBoolean = false;
228+
let isBoolean = function(value) {
229+
let isBoolean = false;
228230
if (value) {
229-
var lowerCaseValue = value.toLowerCase();
231+
let lowerCaseValue = value.toLowerCase();
230232
isBoolean = lowerCaseValue === 'true' || lowerCaseValue === 'false';
231233
}
232234
return isBoolean
@@ -239,11 +241,11 @@
239241
});
240242
}
241243

242-
var dataTypeValidator = function(el) {
243-
var isValid = true;
244-
var value = el.value;
244+
let dataTypeValidator = function(el) {
245+
let isValid = true;
246+
let value = el.value;
245247
if (value) {
246-
var dataType = getSelectedDataType(dialog);
248+
let dataType = getSelectedDataType(dialog);
247249
switch (dataType) {
248250
case 'number':
249251
isValid = !isNaN(value);
@@ -264,7 +266,7 @@
264266
}
265267

266268
static selectElement(tag, selectorValue, bStartsWith, bWithoutTypeHint) {
267-
var $element = null;
269+
let $element = null;
268270
if (bStartsWith) {
269271
$element = $(tag + "[name^='" + selectorValue + "']");
270272
} else {
@@ -277,7 +279,7 @@
277279
}
278280

279281
static showComponent(elem, parentWrapper) {
280-
var parentTag = $(elem).closest(parentWrapper);
282+
let parentTag = $(elem).closest(parentWrapper);
281283
if ($(parentTag).is("[hidden]")) {
282284
$(parentTag).removeAttr("hidden");
283285
} else {
@@ -286,7 +288,7 @@
286288
}
287289

288290
static hideComponent(elem, parentWrapper) {
289-
var parentTag = $(elem).closest(parentWrapper);
291+
let parentTag = $(elem).closest(parentWrapper);
290292
$(parentTag).attr("hidden", "");
291293
}
292294

ui.tests/test-module/specs/numberinput/numberinput.authoring.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ describe('Page - Authoring', function () {
124124
})
125125
});
126126
})
127+
128+
it(' Format should not appear when type is No Pattern', function () {
129+
dropNumberInputInContainer();
130+
cy.openEditableToolbar(sitesSelectors.overlays.overlay.component + numberInputEditPathSelector);
131+
cy.invokeEditableAction(editDialogConfigurationSelector);
132+
cy.get(numberInputBlockBemSelector + '__editdialog').contains('Validation').click().then(() => {
133+
cy.get(numberInputBlockBemSelector + '__editdialog').contains('Formats').click().then(() => {
134+
cy.get(numberInputBlockBemSelector + '__displaypattern').children('button').click();
135+
cy.get('coral-selectlist-item-content').contains('No Pattern').click({force: true}).then(() => {
136+
cy.get('.coral-Form-fieldwrapper').should('be.hidden');
137+
});
138+
cy.get('.cq-dialog-cancel').should('be.visible').click().then(() => {
139+
cy.deleteComponentByPath(numberInputDrop);
140+
})
141+
});
142+
});
143+
})
127144
});
128145

129146
context('Open Sites Editor', function () {

0 commit comments

Comments
 (0)