Skip to content
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

Improved fields dependence (show/hide) in backend's config section #2150

Merged
merged 6 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions app/code/core/Mage/Sales/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ public function prepareProductEditFormRecurringProfile($observer)
$dependencies = $block
->addFieldMap('is_recurring', 'product[is_recurring]')
->addFieldMap($profileElement->getHtmlId(), $profileElement->getName())
->addFieldDependence($profileElement->getName(), 'product[is_recurring]', '1')
->addConfigOptions(['levels_up' => 2]);
->addFieldDependence($profileElement->getName(), 'product[is_recurring]', '1');
$observer->getEvent()->getResult()->output .= $dependencies->toHtml();
}

Expand Down
19 changes: 10 additions & 9 deletions js/mage/adminhtml/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ FormElementDependenceController.prototype = {
* Misc. config options
* Keys are underscored intentionally
*/
_config : {
levels_up : 1 // how many levels up to travel when toggling element
},
_config : {},

getSelectValues : function(select) {
var result = [];
Expand Down Expand Up @@ -512,16 +510,20 @@ FormElementDependenceController.prototype = {
*/
trackChange : function(e, idTo, valuesFrom)
{
let upLevels = this._config.levels_up;
let ele;
if (!$(idTo)) {
var ele = document.getElementById(idTo), cnf = this._config;
if (!ele) {
idTo = 'row_' + idTo;
ele = $(idTo);
if (!ele) {
return;
}
} else {
ele = $(idTo).up(upLevels);
var closest = cnf.levels_up; // @deprecated
if ((typeof closest == 'number') && (closest > 1)) {
ele = ele.up(closest);
} else {
ele = ele.closest('tr');
}
}

// define whether the target should show up
Expand All @@ -548,11 +550,10 @@ FormElementDependenceController.prototype = {

// toggle target row
if (shouldShowUp) {
var currentConfig = this._config;
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)) {
&& !(cnf.can_edit_price != undefined && !cnf.can_edit_price)) {
item.disabled = false;
}
});
Expand Down
Loading