From 1431628ec5de406b7faf5ba2ed06ea02bcbd233d Mon Sep 17 00:00:00 2001 From: Pascal Querner Date: Thu, 8 Jun 2023 08:38:32 +0200 Subject: [PATCH] Allowed system config of type "serialized array" to on another field (#3307) Co-authored-by: Pascal Querner Co-authored-by: Ng Kiat Siong --- js/mage/adminhtml/form.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/js/mage/adminhtml/form.js b/js/mage/adminhtml/form.js index 0837e4096c7..9453a8695ff 100644 --- a/js/mage/adminhtml/form.js +++ b/js/mage/adminhtml/form.js @@ -496,7 +496,12 @@ FormElementDependenceController.prototype = { } return result; }, - + hideElem : function(ele) { + ele.hide(); + }, + showElem : function(ele) { + ele.show(); + }, /** * Define whether target element should be toggled and show/hide its row * @@ -507,8 +512,16 @@ FormElementDependenceController.prototype = { */ trackChange : function(e, idTo, valuesFrom) { + let upLevels = this._config.levels_up; + let ele; if (!$(idTo)) { - return; + idTo = 'row_' + idTo; + ele = $(idTo); + if (!ele) { + return; + } + } else { + ele = $(idTo).up(upLevels); } // define whether the target should show up @@ -536,22 +549,22 @@ FormElementDependenceController.prototype = { // toggle target row if (shouldShowUp) { var currentConfig = this._config; - $(idTo).up(this._config.levels_up).select('input', 'select', 'td').each(function (item) { + ele.select('input', 'select', 'td').each(function (item) { // don't touch hidden inputs (and Use Default inputs too), bc they may have custom logic if ((!item.type || item.type != 'hidden') && !($(item.id+'_inherit') && $(item.id+'_inherit').checked) && !(currentConfig.can_edit_price != undefined && !currentConfig.can_edit_price)) { item.disabled = false; } }); - $(idTo).up(this._config.levels_up).show(); + this.showElem(ele); } else { - $(idTo).up(this._config.levels_up).select('input', 'select', 'td').each(function (item){ + ele.select('input', 'select', 'td', 'div').each(function (item){ // don't touch hidden inputs (and Use Default inputs too), bc they may have custom logic if ((!item.type || item.type != 'hidden') && !($(item.id+'_inherit') && $(item.id+'_inherit').checked)) { item.disabled = true; } }); - $(idTo).up(this._config.levels_up).hide(); + this.hideElem(ele); } } };