Skip to content

Commit 0031a1c

Browse files
author
Javier Villanueva
committed
Fix depends field not working for radio elements
Fixes magento#9360
1 parent f2f94cf commit 0031a1c

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Diff for: lib/web/mage/adminhtml/form.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ define([
386386
* @param {Object} config
387387
*/
388388
initialize: function (elementsMap, config) {
389-
var idTo, idFrom;
389+
var idTo, idFrom, values, fromId, radioFrom;
390390

391391
if (config) {
392392
this._config = config;
@@ -400,10 +400,21 @@ define([
400400
'change',
401401
this.trackChange.bindAsEventListener(this, idTo, elementsMap[idTo])
402402
);
403-
this.trackChange(null, idTo, elementsMap[idTo]);
404403
} else {
405-
this.trackChange(null, idTo, elementsMap[idTo]);
404+
// Check if radio button
405+
values = elementsMap[idTo][idFrom].values;
406+
fromId = $(idFrom + values[0]);
407+
radioFrom = fromId ? $$('[name="' + fromId.name + '"]') : false;
408+
409+
if (radioFrom) {
410+
radioFrom.invoke(
411+
'on',
412+
'change',
413+
this.trackChange.bindAsEventListener(this, idTo, elementsMap[idTo])
414+
);
415+
}
406416
}
417+
this.trackChange(null, idTo, elementsMap[idTo]);
407418
}
408419
}
409420
},
@@ -428,7 +439,7 @@ define([
428439
// define whether the target should show up
429440
var shouldShowUp = true,
430441
idFrom, from, values, isInArray, isNegative, headElement, isInheritCheckboxChecked, target, inputs,
431-
isAnInputOrSelect, currentConfig,rowElement;
442+
isAnInputOrSelect, currentConfig, rowElement, fromId, radioFrom;
432443

433444
for (idFrom in valuesFrom) { //eslint-disable-line guard-for-in
434445
from = $(idFrom);
@@ -441,6 +452,17 @@ define([
441452
if (!from || isInArray && isNegative || !isInArray && !isNegative) {
442453
shouldShowUp = false;
443454
}
455+
// Check if radio button
456+
} else {
457+
values = valuesFrom[idFrom].values;
458+
fromId = $(idFrom + values[0]);
459+
radioFrom = fromId ? $$('[name="' + fromId.name + '"]:checked') : [];
460+
isInArray = radioFrom.length > 0 && values.indexOf(radioFrom[0].value) !== -1;
461+
isNegative = valuesFrom[idFrom].negative;
462+
463+
if (!radioFrom || isInArray && isNegative || !isInArray && !isNegative) {
464+
shouldShowUp = false;
465+
}
444466
}
445467
}
446468

0 commit comments

Comments
 (0)