2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Adds options to clear existing BOM data when uploading

This commit is contained in:
Oliver
2022-02-07 12:20:18 +11:00
parent 4f26df3124
commit 131663cecc
3 changed files with 76 additions and 24 deletions

View File

@ -112,7 +112,7 @@ function constructBomUploadTable(data, options={}) {
// Add callback for "remove row" button
$(`#button-row-remove-${idx}`).click(function() {
$(`#bom_import_row_${idx}`).remove();
$(`#items_${idx}`).remove();
});
}
@ -172,22 +172,36 @@ function submitBomTable(part_id, options={}) {
getApiEndpointOptions(url, function(response) {
var fields = response.actions.POST;
inventreePut(url, data, {
constructForm(url, {
method: 'POST',
success: function(response) {
// TODO: Return to the "bom" page
},
error: function(xhr) {
switch (xhr.status) {
case 400:
handleFormErrors(xhr.responseJSON, fields, options);
break;
default:
showApiError(xhr, url);
break;
}
fields: {
clear_existing: {},
},
title: '{% trans "Submit BOM Data" %}',
onSubmit: function(fields, opts) {
data.clear_existing = getFormFieldValue('clear_existing', {}, opts);
$(opts.modal).modal('hide');
inventreePut(url, data, {
method: 'POST',
success: function(response) {
// TODO: Return to the "bom" page
},
error: function(xhr) {
switch (xhr.status) {
case 400:
handleFormErrors(xhr.responseJSON, fields, options);
break;
default:
showApiError(xhr, url);
break;
}
}
});
}
});
});
});
}

View File

@ -1059,6 +1059,28 @@ function handleNestedErrors(errors, field_name, options={}) {
var errors = error_item[sub_field_name];
if (sub_field_name == 'non_field_errors') {
var row = null;
if (options.modal) {
row = $(options.modal).find(`#items_${nest_id}`);
} else {
row = $(`#items_${nest_id}`);
}
for (var ii = errors.length - 1; ii >= 0; ii--) {
var html = `
<div id='error_${ii}_non_field_error' class='help-block form-field-error form-error-message'>
<strong>${errors[ii]}</strong>
</div>`;
row.after(html);
}
}
// Find the target (nested) field
var target = `${field_name}_${sub_field_name}_${nest_id}`;