mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Display initial errors when importing data
This commit is contained in:
parent
aa962aac83
commit
383835aa89
@ -43,7 +43,7 @@
|
||||
</div>
|
||||
|
||||
<!-- This table is filled out after BOM file is uploaded and processed -->
|
||||
<table class='table table-striped table-condensed' id='bom-import-table'>
|
||||
<table class='table table-condensed' id='bom-import-table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style='max-width: 500px;'>{% trans "Part" %}</th>
|
||||
|
@ -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(
|
||||
{
|
||||
|
@ -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 = `
|
||||
<span id='error_${error_idx}_id_${field_name}' class='help-block form-error-message'>
|
||||
|
Loading…
Reference in New Issue
Block a user