Skip to content

Commit

Permalink
Merge forwardport of #11539 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11539.patch (created by @jahvi) based on commit(s):
  1. 0031a1c

Fixed GitHub Issues in 2.3-develop branch:
  - #9360: <depends> field doesn't work in system.xml for "radios" fields (reported by @WaPoNe)
  • Loading branch information
magento-engcom-team authored Feb 9, 2018
2 parents 1503f3a + 3d5cc51 commit 17662c6
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lib/web/mage/adminhtml/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ define([
* @param {Object} config
*/
initialize: function (elementsMap, config) {
var idTo, idFrom;
var idTo, idFrom, values, fromId, radioFrom;

if (config) {
this._config = config;
Expand All @@ -400,10 +400,21 @@ define([
'change',
this.trackChange.bindAsEventListener(this, idTo, elementsMap[idTo])
);
this.trackChange(null, idTo, elementsMap[idTo]);
} else {
this.trackChange(null, idTo, elementsMap[idTo]);
// Check if radio button
values = elementsMap[idTo][idFrom].values;
fromId = $(idFrom + values[0]);
radioFrom = fromId ? $$('[name="' + fromId.name + '"]') : false;

if (radioFrom) {
radioFrom.invoke(
'on',
'change',
this.trackChange.bindAsEventListener(this, idTo, elementsMap[idTo])
);
}
}
this.trackChange(null, idTo, elementsMap[idTo]);
}
}
},
Expand All @@ -428,7 +439,7 @@ define([
// define whether the target should show up
var shouldShowUp = true,
idFrom, from, values, isInArray, isNegative, headElement, isInheritCheckboxChecked, target, inputs,
isAnInputOrSelect, currentConfig,rowElement;
isAnInputOrSelect, currentConfig, rowElement, fromId, radioFrom;

for (idFrom in valuesFrom) { //eslint-disable-line guard-for-in
from = $(idFrom);
Expand All @@ -441,6 +452,17 @@ define([
if (!from || isInArray && isNegative || !isInArray && !isNegative) {
shouldShowUp = false;
}
// Check if radio button
} else {
values = valuesFrom[idFrom].values;
fromId = $(idFrom + values[0]);
radioFrom = fromId ? $$('[name="' + fromId.name + '"]:checked') : [];
isInArray = radioFrom.length > 0 && values.indexOf(radioFrom[0].value) !== -1;
isNegative = valuesFrom[idFrom].negative;

if (!radioFrom || isInArray && isNegative || !isInArray && !isNegative) {
shouldShowUp = false;
}
}
}

Expand Down

0 comments on commit 17662c6

Please sign in to comment.