From 1754af3d4392ecca28b13281b5e047ff614e51e9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 24 Jun 2021 00:00:20 +1000 Subject: [PATCH] Adds ability to specify which fields are displayed --- InvenTree/templates/js/forms.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index 2db0fdc8dc..1e01de0cc3 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -182,10 +182,25 @@ function constructCreateForm(url, fields, options={}) { var html = ''; + var allowed_fields = options.fields || null; + var ignored_fields = options.ignore || []; + + if (!ignored_fields.includes('pk')) { + ignored_fields.push('pk'); + } + + if (!ignored_fields.includes('id')) { + ignored_fields.push('id'); + } + for (const key in fields) { - // Ignore any PK fields - if (key.toLowerCase() in ['pk', 'id']) { + // Skip over fields + if (allowed_fields && !allowed_fields.includes(key)) { + continue; + } + + if (ignored_fields && ignored_fields.includes(key)) { continue; } @@ -405,9 +420,12 @@ function constructInputOptions(name, classes, type, parameters) { opts.push(`type='${type}'`); - // Existing value? if (parameters.value) { + // Existing value? opts.push(`value='${parameters.value}'`); + } else if (parameters.default) { + // Otherwise, a defualt value? + opts.push(`value='${parameters.default}'`); } // Maximum input length