diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js
index 048747c6bb..7cab63153b 100644
--- a/InvenTree/templates/js/translated/bom.js
+++ b/InvenTree/templates/js/translated/bom.js
@@ -192,30 +192,20 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
rows += renderSubstituteRow(sub);
});
- var html = ``;
-
- if (substitutes.length > 0) {
- html += `
-
-
-
- {% trans "Part" %} |
- {% trans "Description" %} |
- |
-
-
-
- ${rows}
-
-
- `;
- } else {
- html += `
-
- {% trans "There are no substitue parts specified for this BOM line item" %}
-
- `;
- }
+ var html = `
+
+
+
+ {% trans "Part" %} |
+ {% trans "Description" %} |
+ |
+
+
+
+ ${rows}
+
+
+ `;
html += `
@@ -223,6 +213,30 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
`;
+ // Add a callback to remove a row from the table
+ function addRemoveCallback(modal, element) {
+ $(modal).find(element).click(function() {
+ var pk = $(this).attr('pk');
+
+ var pre = `
+
+ {% trans "Are you sure you wish to remove this substitute part link?" %}
+
+ `;
+
+ constructForm(`/api/bom/substitute/${pk}/`, {
+ method: 'DELETE',
+ title: '{% trans "Remove Substitute Part" %}',
+ preFormContent: pre,
+ confirm: true,
+ onSuccess: function() {
+ $(modal).find(`#substitute-row-${pk}`).remove();
+ reloadParentTable();
+ }
+ });
+ });
+ }
+
constructForm('{% url "api-bom-substitute-list" %}', {
method: 'POST',
fields: {
@@ -239,29 +253,7 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
submitText: '{% trans "Add Substitute" %}',
title: '{% trans "Edit BOM Item Substitutes" %}',
afterRender: function(fields, opts) {
-
- // Add a callback to remove individual rows
- $(opts.modal).find('.button-row-remove').click(function() {
- var pk = $(this).attr('pk');
-
- var pre = `
-
- {% trans "Are you sure you wish to remove this substitute part link?" %}
-
- `;
-
- constructForm(`/api/bom/substitute/${pk}/`, {
- method: 'DELETE',
- title: '{% trans "Remove Substitute Part" %}',
- preFormContent: pre,
- confirm: true,
- onSuccess: function() {
- $(opts.modal).find(`#substitute-row-${pk}`).remove();
-
- reloadParentTable();
- }
- });
- });
+ addRemoveCallback(opts.modal, '.button-row-remove');
},
preventClose: true,
onSuccess: function(response, opts) {
@@ -277,6 +269,9 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
var row = renderSubstituteRow(response);
$(opts.modal).find('#substitute-table > tbody:last-child').append(row);
+ // Add a callback to the new button
+ addRemoveCallback(opts.modal, `#button-row-remove-${response.pk}`);
+
// Re-enable the "submit" button
$(opts.modal).find('#modal-form-submit').prop('disabled', false);