From 9f5618a51fabf78257fbbddaf31c18ff39e15638 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 28 Feb 2022 23:57:28 +1100 Subject: [PATCH] Adds option to reload a form after success, rather than dismissing it --- InvenTree/templates/js/translated/forms.js | 53 +++++++++++++++------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index 9ee3dcace3..d5be70e4fe 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -934,16 +934,14 @@ function getFormFieldValue(name, field={}, options={}) { */ function handleFormSuccess(response, options) { - // Close the modal - if (!options.preventClose) { - // Note: The modal will be deleted automatically after closing - $(options.modal).modal('hide'); - } - // Display any required messages // Should we show alerts immediately or cache them? var cache = (options.follow && response.url) || options.redirect || options.reload; + if (options.reloadFormAfterSuccess) { + cache = false; + } + // Display any messages if (response && (response.success || options.successMessage)) { showAlertOrCache(response.success || options.successMessage, cache, {style: 'success'}); @@ -960,21 +958,42 @@ function handleFormSuccess(response, options) { if (response && response.danger) { showAlertOrCache(response.danger, cache, {style: 'danger'}); } - + if (options.onSuccess) { // Callback function options.onSuccess(response, options); } - if (options.follow && response.url) { - // Follow the returned URL - window.location.href = response.url; - } else if (options.reload) { - // Reload the current page - location.reload(); - } else if (options.redirect) { - // Redirect to a specified URL - window.location.href = options.redirect; + if (options.reloadFormAfterSuccess) { + // Instead of closing the form and going somewhere else, + // reload (empty) the form so the user can input more data + + // Reset the status of the "submit" button + if (options.modal) { + $(options.modal).find('#modal-form-submit').prop('disabled', false); + } + + // Remove any error flags from the form + clearFormErrors(options); + + } else { + + // Close the modal + if (!options.preventClose) { + // Note: The modal will be deleted automatically after closing + $(options.modal).modal('hide'); + } + + if (options.follow && response.url) { + // Follow the returned URL + window.location.href = response.url; + } else if (options.reload) { + // Reload the current page + location.reload(); + } else if (options.redirect) { + // Redirect to a specified URL + window.location.href = options.redirect; + } } } @@ -988,6 +1007,8 @@ function clearFormErrors(options={}) { if (options && options.modal) { // Remove the individual error messages $(options.modal).find('.form-error-message').remove(); + + $(options.modal).find('.modal-content').removeClass('modal-error'); // Remove the "has error" class $(options.modal).find('.form-field-error').removeClass('form-field-error');