diff --git a/InvenTree/part/templates/part/upload_bom.html b/InvenTree/part/templates/part/upload_bom.html index 27f681acae..07213069a6 100644 --- a/InvenTree/part/templates/part/upload_bom.html +++ b/InvenTree/part/templates/part/upload_bom.html @@ -43,7 +43,7 @@ - +
diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index fd23e70ad0..aeaa1d933d 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -40,6 +40,12 @@ function constructBomUploadTable(data, options={}) { function constructRow(row, idx, fields) { // Construct an individual row from the provided data + var errors = {}; + + if (data.errors && data.errors.length > idx) { + errors = data.errors[idx]; + } + var field_options = { hideLabels: true, hideClearButton: true, @@ -92,6 +98,15 @@ function constructBomUploadTable(data, options={}) { $('#bom-import-table tbody').append(html); + // Handle any errors raised by initial data import + if (errors.part) { + addFieldErrorMessage(`items_sub_part_${idx}`, errors.part); + } + + if (errors.quantity) { + addFieldErrorMessage(`items_quantity_${idx}`, errors.quantity); + } + // Initialize the "part" selector for this row initializeRelatedField( { diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index fe912b3358..394c18a568 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -1196,13 +1196,13 @@ function handleFormErrors(errors, fields={}, options={}) { /* * Add a rendered error message to the provided field */ -function addFieldErrorMessage(name, error_text, error_idx, options={}) { +function addFieldErrorMessage(name, error_text, error_idx=0, options={}) { field_name = getFieldName(name, options); var field_dom = null; - if (options.modal) { + if (options && options.modal) { $(options.modal).find(`#div_id_${field_name}`).addClass('form-field-error'); field_dom = $(options.modal).find(`#errors-${field_name}`); } else { @@ -1210,7 +1210,7 @@ function addFieldErrorMessage(name, error_text, error_idx, options={}) { field_dom = $(`#errors-${field_name}`); } - if (field_dom) { + if (field_dom.exists()) { var error_html = `
{% trans "Part" %}