Skip to content

Commit

Permalink
Fix depends field not working for radio elements
Browse files Browse the repository at this point in the history
Fixes #9360
  • Loading branch information
Javier Villanueva committed Nov 21, 2017
1 parent f2f94cf commit 0031a1c
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 0031a1c

Please sign in to comment.