diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index 914eb93dec..a5f4f56bc9 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -366,6 +366,14 @@ function constructFormBody(fields, options) { } } + // Initialize an "empty" field for each specified field + for (field in displayed_fields) { + if (!(field in fields)) { + console.log("adding blank field for ", field); + fields[field] = {}; + } + } + // Provide each field object with its own name for(field in fields) { fields[field].name = field; @@ -383,57 +391,18 @@ function constructFormBody(fields, options) { // Override existing query filters (if provided!) fields[field].filters = Object.assign(fields[field].filters || {}, field_options.filters); - // TODO: Refactor the following code with Object.assign (see above) + for (var opt in field_options) { - // "before" and "after" renders - fields[field].before = field_options.before; - fields[field].after = field_options.after; + var val = field_options[opt]; - // Secondary modal options - fields[field].secondary = field_options.secondary; - - // Edit callback - fields[field].onEdit = field_options.onEdit; - - fields[field].multiline = field_options.multiline; - - // Custom help_text - if (field_options.help_text) { - fields[field].help_text = field_options.help_text; - } - - // Custom label - if (field_options.label) { - fields[field].label = field_options.label; - } - - // Custom placeholder - if (field_options.placeholder) { - fields[field].placeholder = field_options.placeholder; - } - - // Choices - if (field_options.choices) { - fields[field].choices = field_options.choices; - } - - // Group - if (field_options.group) { - fields[field].group = field_options.group; - } - - // Field prefix - if (field_options.prefix) { - fields[field].prefix = field_options.prefix; - } else if (field_options.icon) { - // Specify icon like 'fa-user' - fields[field].prefix = ``; - } - - fields[field].hidden = field_options.hidden; - - if (field_options.read_only != null) { - fields[field].read_only = field_options.read_only; + if (opt == 'filters') { + // ignore filters (see above) + } else if (opt == 'icon') { + // Specify custom icon + fields[field].prefix = ``; + } else { + fields[field][opt] = field_options[opt]; + } } } } @@ -477,8 +446,6 @@ function constructFormBody(fields, options) { if (options.current_group) { // Close out the current group html += ``; - - console.log(`finally, ending group '${console.current_group}'`); } // Create a new modal if one does not exists @@ -878,6 +845,7 @@ function handleFormErrors(errors, fields, options) { non_field_errors.append( `
{% trans "Form errors exist" %} +
` ); @@ -947,7 +915,10 @@ function addFieldCallbacks(fields, options) { function addFieldCallback(name, field, options) { $(options.modal).find(`#id_${name}`).change(function() { - field.onEdit(name, field, options); + + var value = getFormFieldValue(name, field, options); + + field.onEdit(value, name, field, options); }); } @@ -1429,8 +1400,6 @@ function constructField(name, parameters, options) { if (options.current_group && parameters.group != options.current_group) { html += ``; - console.log(`ending group '${options.current_group}'`); - // Null out the current "group" so we can start a new one options.current_group = null; } @@ -1446,8 +1415,6 @@ function constructField(name, parameters, options) { // Add HTML for the start of a separate panel if (parameters.group != options.current_group) { - console.log(`starting group '${group}'`); - html += `
`;