From 81271bf6b970e95753e1f70f3b65d853b0c29bfc Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 5 Feb 2022 10:01:07 +1100 Subject: [PATCH] Add "clear input" callback function --- InvenTree/templates/js/translated/bom.js | 13 +++++++++++-- InvenTree/templates/js/translated/forms.js | 10 ++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index 4fa178923c..3106c3b9f0 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -69,13 +69,14 @@ function constructBomUploadTable(data, options={}) { var buttons = `
`; - buttons += makeIconButton('fa-file-alt', 'button-row-data', idx, '{% trans "Display row data" %}'); + // buttons += makeIconButton('fa-file-alt', 'button-row-data', idx, '{% trans "Display row data" %}'); buttons += makeIconButton('fa-times icon-red', 'button-row-remove', idx, '{% trans "Remove row" %}'); buttons += `
`; var html = ` + ${buttons} ${sub_part} ${quantity} ${reference} @@ -84,7 +85,6 @@ function constructBomUploadTable(data, options={}) { ${inherited} ${optional} ${note} - ${buttons} `; $('#bom-import-table tbody').append(html); @@ -111,6 +111,15 @@ function constructBomUploadTable(data, options={}) { $(`#button-row-remove-${idx}`).click(function() { $(`#bom_import_row_${idx}`).remove(); }); + + // Add callbacks for the fields which allow it + function addRowClearCallback(field_name) { + addClearCallback(`${field_name}_${idx}`, fields[field_name]); + } + + addRowClearCallback('reference'); + addRowClearCallback('overage'); + addRowClearCallback('note'); } // Request API endpoint options diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index dda79f2737..e5cb571a58 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -1240,8 +1240,14 @@ function addClearCallback(name, field, options) { var field_name = getFieldName(name, options); - var el = $(options.modal).find(`#clear_${field_name}`); - + var el = null; + + if (options && options.modal) { + el = $(options.modal).find(`#clear_${field_name}`); + } else { + el = $(`#clear_${field_name}`); + } + if (!el) { console.log(`WARNING: addClearCallback could not find field '${name}'`); return;