diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index 8a302bc2b1..c6d515a620 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -365,7 +365,7 @@ function submitFormData(fields, options) { { method: options.method, success: function(response, status) { - console.log('success', '->', status); + handleFormSuccess(response, options); }, error: function(xhr, status, thrownError) { @@ -383,6 +383,31 @@ function submitFormData(fields, options) { } +/* + * Handle successful form posting + * + * arguments: + * - response: The JSON response object from the server + * - options: The original options object provided by the client + */ +function handleFormSuccess(response, options) { + + // Close the modal + if (!options.preventClose) { + // TODO: Actually just *delete* the modal, + // rather than hiding it!! + $(options.modal).modal('hide'); + } + + if (response.url) { + // GOTO + window.location.href = response.url; + } + +} + + + /* * Remove all error text items from the form */ @@ -664,10 +689,6 @@ function constructField(name, parameters, options) { html += constructInput(name, parameters, options); - if (parameters.errors) { - html += constructErrorMessage(name, parameters, options); - } - if (parameters.help_text) { html += constructHelpText(name, parameters, options); } @@ -941,36 +962,7 @@ function constructRelatedFieldInput(name, parameters, options) { */ function constructHelpText(name, parameters, options) { - var html = `
${parameters.help_text}
`; + var html = `
${parameters.help_text}
`; return html; -} - - -/* - * Construct an 'error message' div for the field - * - * arguments: - * - name: The name of the field - * - parameters: Field parameters returned by the OPTIONS method - */ -function constructErrorMessage(name, parameters, options) { - - var errors_html = ''; - - for (var idx = 0; idx < parameters.errors.length; idx++) { - - var err = parameters.errors[idx]; - - var html = ''; - - html += ``; - html += `${err}`; - html += ``; - - errors_html += html; - - } - - return errors_html; } \ No newline at end of file