From 8a86932c7b1d69f36821ffa9410e5ee9e1843209 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 5 Feb 2022 01:36:46 +1100 Subject: [PATCH] Initialize related field for "part" selection --- InvenTree/templates/js/translated/bom.js | 9 +++++++++ InvenTree/templates/js/translated/forms.js | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index 798c6749ec..5b1c7e2bb2 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -50,6 +50,13 @@ function constructBomUploadTable(data, options={}) { } ); + var buttons = `
`; + + 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 = ` ${part_input} @@ -60,6 +67,7 @@ function constructBomUploadTable(data, options={}) { inherited optional note + ${buttons} `; $('#bom-import-table tbody').append(html); @@ -68,6 +76,7 @@ function constructBomUploadTable(data, options={}) { initializeRelatedField( { name: `part_${idx}`, + value: row.part, api_url: '{% url "api-part-list" %}', filters: { component: true, diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index ff4415404f..c2addc3594 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -1484,10 +1484,19 @@ function initializeRelatedField(field, fields, options={}) { // limit size for AJAX requests var pageSize = options.pageSize || 25; + var parent = null; + var auto_width = true; + + // Special considerations if the select2 input is a child of a modal + if (options && options.modal) { + parent = $(options.modal); + auto_width = true; + } + select.select2({ placeholder: '', - dropdownParent: $(options.modal), - dropdownAutoWidth: false, + dropdownParent: parent, + dropdownAutoWidth: auto_width, language: { noResults: function(query) { if (field.noResults) {