From 047b9d1ecda774f2bd5d6b40b3f5eab1874b186b Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 2 Jul 2021 17:19:58 +1000 Subject: [PATCH] Capture enter key to submit form --- InvenTree/templates/js/modals.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index 319158eaa0..8e32045c19 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -53,11 +53,33 @@ function createNewModal(options={}) { var modal_name = `#modal-form-${id}`; + $(modal_name).on('shown.bs.modal', function() { + $(modal_name + ' .modal-form-content').scrollTop(0); + }); + // Automatically remove the modal when it is deleted! $(modal_name).on('hidden.bs.modal', function(e) { $(modal_name).remove(); }); + // Capture "enter" key input + $(modal_name).on('keydown', 'input', function(event) { + + + if (event.keyCode == 13) { + event.preventDefault(); + // Simulate a click on the 'Submit' button + $(modal_name).find("#modal-form-submit").click(); + + return false; + } + }); + + $(modal_name).modal({ + backdrop: 'static', + keyboard: false, + }); + // Set labels based on supplied options modalSetTitle(modal_name, options.title || '{% trans "Form Title" %}'); modalSetSubmitText(modal_name, options.submitText || '{% trans "Submit" %}');