From 337223b8eb858601e26a53a0ec4908340fb6b11a Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 9 Jul 2021 01:20:40 +1000 Subject: [PATCH] Modal form improvements --- InvenTree/templates/js/forms.js | 24 ++++++++++++++++++++++-- InvenTree/templates/js/modals.js | 2 -- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index 1de62dd3f5..f764ea9062 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -732,11 +732,31 @@ function handleFormSuccess(response, options) { // Close the modal if (!options.preventClose) { - // TODO: Actually just *delete* the modal, - // rather than hiding it!! + // 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; + + // Display any messages + if (response.success) { + showAlertOrCache("alert-success", response.success, cache); + } + + if (response.info) { + showAlertOrCache("alert-info", response.info, cache); + } + + if (response.warning) { + showAlertOrCache("alert-warning", response.warning, cache); + } + + if (response.danger) { + showAlertOrCache("alert-danger", response.danger, cache); + } + if (options.onSuccess) { // Callback function options.onSuccess(response, options); diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index d0f9f742f8..b613ed81f6 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -83,8 +83,6 @@ function createNewModal(options={}) { // Capture "enter" key input $(modal_name).on('keydown', 'input', function(event) { - - if (event.keyCode == 13) { event.preventDefault(); // Simulate a click on the 'Submit' button