Skip to content

Fix depends field not working for radio elements #11539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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