fix the git revert mess - adding the required form js code for onInputcallback

This commit is contained in:
rocheparadox 2024-08-24 18:08:33 +00:00
parent ae8d178475
commit ac3b2b4afb
2 changed files with 11 additions and 9 deletions

View File

@ -298,7 +298,8 @@ function constructDeleteForm(fields, options) {
* - closeText: Text for the "close" button * - closeText: Text for the "close" button
* - fields: list of fields to display, with the following options * - fields: list of fields to display, with the following options
* - filters: API query filters * - 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 * - secondary: Define a secondary modal form for this field
* - label: Specify custom label * - label: Specify custom label
* - help_text: Specify custom help_text * - help_text: Specify custom help_text
@ -1645,20 +1646,21 @@ function addFieldCallbacks(fields, options) {
function addFieldCallback(name, field, options) { function addFieldCallback(name, field, options) {
const el = getFormFieldElement(name, options); const el = getFormFieldElement(name, options);
if (field.onEdit) { if(field.onInput){
el.change(function() {
el.on('input', function(){
var value = getFormFieldValue(name, field, options); var value = getFormFieldValue(name, field, options);
let onEditHandlers = field.onEdit; let onInputHandlers = field.onInput;
if (!Array.isArray(onEditHandlers)) { if (!Array.isArray(onInputHandlers)) {
onEditHandlers = [onEditHandlers]; onInputHandlers = [onInputHandlers];
} }
for (const onEdit of onEditHandlers) { for (const onInput of onInputHandlers) {
onEdit(value, name, field, options); onInput(value, name, field, options);
} }
}); });
} }
// attach field callback for nested fields // attach field callback for nested fields

View File

@ -343,7 +343,7 @@ function poLineItemFields(options={}) {
reference: {}, reference: {},
purchase_price: { purchase_price: {
icon: 'fa-dollar-sign', icon: 'fa-dollar-sign',
onEdit: function(value, name, field, opts) { onInput: function(value, name, field, opts) {
updateFieldValue('auto_pricing', value === '', {}, opts); updateFieldValue('auto_pricing', value === '', {}, opts);
} }
}, },