diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index 7bb160eccb..4fa178923c 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -35,20 +35,37 @@ function constructBomUploadTable(data, options={}) { // TODO: Error message! return; } - - function constructRow(row, idx) { + + function constructRow(row, idx, fields) { // Construct an individual row from the provided data - var part_input = constructField( - `part_${idx}`, - { - type: 'related field', - required: 'true', - }, - { - hideLabels: true, + var field_options = { + hideLabels: true, + }; + + function constructRowField(field_name) { + + var field = fields[field_name] || null; + + if (!field) { + return `Cannot render field '${field_name}`; } - ); + + field.value = row[field_name]; + + return constructField(`${field_name}_${idx}`, field, field_options); + + } + + // Construct form inputs + var sub_part = constructRowField('sub_part'); + var quantity = constructRowField('quantity'); + var reference = constructRowField('reference'); + var overage = constructRowField('overage'); + var variants = constructRowField('allow_variants'); + var inherited = constructRowField('inherited'); + var optional = constructRowField('optional'); + var note = constructRowField('note'); var buttons = `
`; @@ -59,14 +76,14 @@ function constructBomUploadTable(data, options={}) { var html = ` - ${part_input} - quantity - reference - overage - variants - inherited - optional - note + ${sub_part} + ${quantity} + ${reference} + ${overage} + ${variants} + ${inherited} + ${optional} + ${note} ${buttons} `; @@ -75,7 +92,7 @@ function constructBomUploadTable(data, options={}) { // Initialize the "part" selector for this row initializeRelatedField( { - name: `part_${idx}`, + name: `sub_part_${idx}`, value: row.part, api_url: '{% url "api-part-list" %}', filters: { @@ -96,8 +113,14 @@ function constructBomUploadTable(data, options={}) { }); } - data.rows.forEach(function(row, idx) { - constructRow(row, idx); + // Request API endpoint options + getApiEndpointOptions('{% url "api-bom-list" %}', function(response) { + + var fields = response.actions.POST; + + data.rows.forEach(function(row, idx) { + constructRow(row, idx, fields); + }); }); } diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index c2addc3594..dda79f2737 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -2071,7 +2071,7 @@ function constructInput(name, parameters, options) { // Construct a set of default input options which apply to all input types -function constructInputOptions(name, classes, type, parameters) { +function constructInputOptions(name, classes, type, parameters, options={}) { var opts = []; @@ -2153,11 +2153,18 @@ function constructInputOptions(name, classes, type, parameters) { if (parameters.multiline) { return ``; } else if (parameters.type == 'boolean') { + + var help_text = ''; + + if (!options.hideLabels && parameters.help_text) { + help_text = `${parameters.help_text}`; + } + return `
`; @@ -2180,13 +2187,14 @@ function constructHiddenInput(name, parameters) { // Construct a "checkbox" input -function constructCheckboxInput(name, parameters) { +function constructCheckboxInput(name, parameters, options={}) { return constructInputOptions( name, 'form-check-input', 'checkbox', - parameters + parameters, + options ); }