From 3d5cc519f30a8664aadca0b1378ff62138fd1bf9 Mon Sep 17 00:00:00 2001 From: Magento EngCom Team Date: Wed, 24 Jan 2018 12:09:54 -0600 Subject: [PATCH] :arrow_double_up: Forwardport of magento/magento2#11539 to 2.3-develop branch Applied pull request patch https://github.com/magento/magento2/pull/11539.patch (created by @jahvi) based on commit(s): 1. 0031a1c56b5277149e3cdc567251c19dbcf8df12 Fixed GitHub Issues in 2.3-develop branch: - magento/magento2#9360: field doesn't work in system.xml for "radios" fields (reported by @WaPoNe) --- lib/web/mage/adminhtml/form.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/web/mage/adminhtml/form.js b/lib/web/mage/adminhtml/form.js index 0053dce8207dd..2bd3ef86e8f90 100644 --- a/lib/web/mage/adminhtml/form.js +++ b/lib/web/mage/adminhtml/form.js @@ -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; @@ -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]); } } }, @@ -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); @@ -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; + } } }