Skip to content

Commit f6d46b2

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4337' into PR_2025_12_11_muntianu
2 parents 02dadc4 + 4caf778 commit f6d46b2

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Copyright 2025 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+
var container = document.createElement('div'),
27+
target = document.createElement('input'),
28+
cssDisabled = document.createElement('input'),
29+
normalInput = document.createElement('input'),
30+
source = document.createElement('input'),
31+
originalObserve = window.Event && window.Event.observe,
32+
originalDollar = window.$,
33+
fakeTarget = {
34+
id: 'test_input_dependent',
35+
type: 'input',
36+
tagName: 'INPUT',
37+
getAttribute: function () {
38+
return null;
39+
},
40+
show: function () {},
41+
hide: function () {},
42+
up: function () {
43+
return {
44+
show: function () {},
45+
hide: function () {},
46+
select: function () {
47+
return [cssDisabled, normalInput];
48+
}
49+
};
50+
}
51+
};
52+
53+
document.body.appendChild(container);
54+
target.id = 'test_input_dependent';
55+
container.appendChild(target);
56+
cssDisabled.id = 'css_disabled_input';
57+
cssDisabled.className = 'disabled';
58+
cssDisabled.disabled = true;
59+
container.appendChild(cssDisabled);
60+
normalInput.id = 'normal_input';
61+
normalInput.disabled = true;
62+
container.appendChild(normalInput);
63+
source.id = 'dep_source';
64+
source.value = '1';
65+
document.body.appendChild(source);
66+
67+
if (window.Event) {
68+
window.Event.observe = function () {};
69+
}
70+
71+
window.$ = function (elemId) {
72+
if (elemId === 'test_input_dependent') {
73+
return fakeTarget;
74+
}
75+
return document.getElementById(elemId);
76+
};
77+
/* eslint-disable no-new */
78+
new window.FormElementDependenceController({
79+
'test_input_dependent': {
80+
'dep_source': { values: ['1'] }
81+
}
82+
}, {
83+
levels_up: 1
84+
});
85+
/* eslint-enable no-new */
86+
87+
// The element with CSS class "disabled" must remain disabled
88+
expect(cssDisabled.disabled).toBe(true);
89+
// The normal input should be enabled because dependencies are satisfied
90+
expect(normalInput.disabled).toBe(false);
91+
92+
// Cleanup
93+
if (window.Event && originalObserve) {
94+
window.Event.observe = originalObserve;
95+
}
96+
if (originalDollar) {
97+
window.$ = originalDollar;
98+
}
99+
document.body.removeChild(container);
100+
document.body.removeChild(source);
101+
});
102+
});
103+
});

lib/web/mage/adminhtml/form.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ define([
378378
try {
379379
return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)); //eslint-disable-line
380380
}
381-
catch (e) {}
381+
catch (e) {} // eslint-disable-line no-unused-vars
382382
};
383383

384384
/**
@@ -389,7 +389,7 @@ define([
389389
try {
390390
return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)); //eslint-disable-line
391391
}
392-
catch (e) {}
392+
catch (e) {} // eslint-disable-line no-unused-vars
393393
};
394394

395395
/**
@@ -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)