Skip to content

Commit ef78ce5

Browse files
committed
ACP2E-4337: Configuration With Dependency Config Editable When Use Default Checked in Store Configuration
1 parent 0a3b703 commit ef78ce5

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright 2014 Adobe
3+
* All Rights Reserved.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'mage/adminhtml/form'
9+
], function ($) {
10+
'use strict';
11+
12+
describe('mage/adminhtml/form', function () {
13+
var id = 'edit_form',
14+
elementId = '#' + id;
15+
16+
beforeEach(function () {
17+
var element = $('<form id="' + id + '" action="action/url" method="GET" target="_self" ></form>');
18+
19+
element.appendTo('body');
20+
});
21+
afterEach(function () {
22+
$(elementId).remove();
23+
});
24+
25+
it('should not enable inputs that have the disabled CSS class when dependencies are satisfied', function () {
26+
// Container that will be traversed with levels_up = 1
27+
var container = document.createElement('div');
28+
document.body.appendChild(container);
29+
30+
// Target element (idTo) inside the container
31+
var target = document.createElement('input');
32+
target.id = 'test_input_dependent';
33+
container.appendChild(target);
34+
35+
// Sibling input that carries CSS class "disabled" and is disabled initially
36+
var cssDisabled = document.createElement('input');
37+
cssDisabled.id = 'css_disabled_input';
38+
cssDisabled.className = 'disabled';
39+
cssDisabled.disabled = true;
40+
container.appendChild(cssDisabled);
41+
42+
// Another sibling input which is disabled initially but should be enabled after dependencies are met
43+
var normalInput = document.createElement('input');
44+
normalInput.id = 'normal_input';
45+
normalInput.disabled = true;
46+
container.appendChild(normalInput);
47+
48+
// Dependency source element that satisfies the map
49+
var source = document.createElement('input');
50+
source.id = 'dep_source';
51+
source.value = '1';
52+
document.body.appendChild(source);
53+
54+
// Initialize controller with dependency that evaluates to true (shouldShowUp = true)
55+
/* eslint-disable no-new */
56+
new window.FormElementDependenceController({
57+
'test_input_dependent': {
58+
'dep_source': { values: ['1'] }
59+
}
60+
}, {
61+
levels_up: 1
62+
});
63+
/* eslint-enable no-new */
64+
65+
// The element with CSS class "disabled" must remain disabled
66+
expect(cssDisabled.disabled).toBe(true);
67+
// The normal input should be enabled because dependencies are satisfied
68+
expect(normalInput.disabled).toBe(false);
69+
70+
// Cleanup
71+
document.body.removeChild(container);
72+
document.body.removeChild(source);
73+
});
74+
});
75+
});

lib/web/mage/adminhtml/form.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ define([
531531
inputs.each(function (item) {
532532
// don't touch hidden inputs (and Use Default inputs too), bc they may have custom logic
533533
if ((!item.type || item.type != 'hidden') && !($(item.id + '_inherit') && $(item.id + '_inherit').checked) && //eslint-disable-line
534+
!jQuery(item).hasClass('disabled') &&
534535
!(currentConfig['can_edit_price'] != undefined && !currentConfig['can_edit_price']) && //eslint-disable-line
535536
!item.getAttribute('readonly') || isChooser //eslint-disable-line
536537
) {

0 commit comments

Comments
 (0)