Skip to content

Commit 873bdae

Browse files
dgjlindsayclaude
andcommitted
ABN-298/feat: reset field values on "Use System Value" re-check
Snapshots field values when inherit checkbox is unchecked (field still shows system value at that moment), restores on re-check. Triggers change event so dependent visibility updates cascade. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0937489 commit 873bdae

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

view/adminhtml/web/js/payment-terms-config.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,46 @@ define(['jquery', 'domReady!'], function ($) {
131131
$defaultTerm.on('change', onDefaultTermChanged);
132132
$('#two_payment_payment_terms_surcharge_type_inherit').on('change', onSurchargeChanged);
133133

134+
// ── "Use System Value" reset ────────────────────────────────────
135+
136+
function initInheritResetBehavior() {
137+
var prefix = 'two_payment_payment_terms_';
138+
$('input[id^="' + prefix + '"][id$="_inherit"]').each(function () {
139+
var $inherit = $(this);
140+
var fieldId = $inherit.attr('id').replace(/_inherit$/, '');
141+
var $field = $('#' + fieldId);
142+
if (!$field.length) {
143+
return;
144+
}
145+
146+
var systemValue = null;
147+
148+
// If inherit is checked on load, current value IS the system value
149+
if ($inherit.is(':checked')) {
150+
systemValue = $field.val();
151+
}
152+
153+
$inherit.on('change', function () {
154+
if ($inherit.is(':checked')) {
155+
// Re-checking: restore system value if we have it
156+
if (systemValue !== null) {
157+
$field.val(systemValue);
158+
$field.trigger('change');
159+
}
160+
} else {
161+
// Unchecking: field still shows system value — snapshot it
162+
systemValue = $field.val();
163+
}
164+
});
165+
});
166+
}
167+
134168
// ── Initialize ───────────────────────────────────────────────────
135169

136170
updateDefaultTermOptions();
137171
updateDifferentialOptionLabel();
138172
updateSurchargeVisibility();
173+
initInheritResetBehavior();
139174
}
140175

141176
$(document).ready(function () {

0 commit comments

Comments
 (0)