diff --git a/InvenTree/company/templates/company/index.html b/InvenTree/company/templates/company/index.html index 2f7319fb74..28129b1f36 100644 --- a/InvenTree/company/templates/company/index.html +++ b/InvenTree/company/templates/company/index.html @@ -46,6 +46,11 @@ fields: [ 'name', 'description', + 'website', + 'address', + 'phone', + 'email', + 'contact', 'is_supplier', 'is_manufacturer', 'is_customer', diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index b33f5048b3..7d6cc5cd98 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -110,6 +110,16 @@ function getApiEndpointOptions(url, callback, options) { */ function constructCreateForm(fields, options) { + // Check if default values were provided for any fields + for (const name in fields) { + + var field = fields[name]; + + if (field.default != null) { + field.value = field.default; + } + } + // We should have enough information to create the form! constructFormBody(fields, options); } @@ -320,6 +330,8 @@ function constructFormBody(fields, options) { $(modal).modal('show'); + updateFieldValues(fields, options); + // Setup related fields initializeRelatedFields(fields, options) @@ -387,6 +399,41 @@ function submitFormData(fields, options) { } +/* + * Update (set) the field values based on the specified data. + * + * Iterate through each of the displayed fields, + * and set the 'val' attribute of each one. + * + */ +function updateFieldValues(fields, options) { + + for (var idx = 0; idx < options.field_names.length; idx++) { + + var name = options.field_names[idx]; + + var field = fields[name] || null; + + if (field == null) { continue; } + + var value = field.value || field.default || null; + + if (value == null) { continue; } + + var el = $(options.modal).find(`#id_${name}`); + + switch (field.type) { + case 'boolean': + el.prop('checked', value); + break; + default: + el.val(value); + break; + } + } +} + + /* * Extract and field value before sending back to the server * @@ -409,7 +456,6 @@ function getFormFieldValue(name, field, options) { } - /* * Handle successful form posting *