From ac3b2b4afb772d898e28a28bd95a0ab13935b221 Mon Sep 17 00:00:00 2001 From: rocheparadox Date: Sat, 24 Aug 2024 18:08:33 +0000 Subject: [PATCH] fix the git revert mess - adding the required form js code for onInputcallback --- .../InvenTree/templates/js/translated/forms.js | 18 ++++++++++-------- .../templates/js/translated/purchase_order.js | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/backend/InvenTree/templates/js/translated/forms.js b/src/backend/InvenTree/templates/js/translated/forms.js index 4b6d7ed364..38a8df0c40 100644 --- a/src/backend/InvenTree/templates/js/translated/forms.js +++ b/src/backend/InvenTree/templates/js/translated/forms.js @@ -298,7 +298,8 @@ function constructDeleteForm(fields, options) { * - closeText: Text for the "close" button * - fields: list of fields to display, with the following options * - filters: API query filters - * - onEdit: callback or array of callbacks which get fired when field is edited + * - onEdit: callback or array of callbacks which get fired when field is edited - does not get triggered until the field loses focus, ref: https://api.jquery.com/change/ + * - onInput: callback or array of callbacks which get fired when an input is detected in the field * - secondary: Define a secondary modal form for this field * - label: Specify custom label * - help_text: Specify custom help_text @@ -1645,20 +1646,21 @@ function addFieldCallbacks(fields, options) { function addFieldCallback(name, field, options) { const el = getFormFieldElement(name, options); - if (field.onEdit) { - el.change(function() { + if(field.onInput){ + el.on('input', function(){ var value = getFormFieldValue(name, field, options); - let onEditHandlers = field.onEdit; + let onInputHandlers = field.onInput; - if (!Array.isArray(onEditHandlers)) { - onEditHandlers = [onEditHandlers]; + if (!Array.isArray(onInputHandlers)) { + onInputHandlers = [onInputHandlers]; } - for (const onEdit of onEditHandlers) { - onEdit(value, name, field, options); + for (const onInput of onInputHandlers) { + onInput(value, name, field, options); } }); + } // attach field callback for nested fields diff --git a/src/backend/InvenTree/templates/js/translated/purchase_order.js b/src/backend/InvenTree/templates/js/translated/purchase_order.js index 4cccc74bb2..33f3f24f2b 100644 --- a/src/backend/InvenTree/templates/js/translated/purchase_order.js +++ b/src/backend/InvenTree/templates/js/translated/purchase_order.js @@ -343,7 +343,7 @@ function poLineItemFields(options={}) { reference: {}, purchase_price: { icon: 'fa-dollar-sign', - onEdit: function(value, name, field, opts) { + onInput: function(value, name, field, opts) { updateFieldValue('auto_pricing', value === '', {}, opts); } },