diff --git a/InvenTree/InvenTree/static/script/inventree/modals.js b/InvenTree/InvenTree/static/script/inventree/modals.js index a17cee0d2c..1cb5346a68 100644 --- a/InvenTree/InvenTree/static/script/inventree/modals.js +++ b/InvenTree/InvenTree/static/script/inventree/modals.js @@ -469,6 +469,9 @@ function openModal(options) { $(modal).on('shown.bs.modal', function() { $(modal + ' .modal-form-content').scrollTop(0); + if (options.focus) { + getFieldByName(modal, options.focus).focus(); + } }); // Prevent 'enter' key from submitting the form using the normal method @@ -745,6 +748,7 @@ function launchModalForm(url, options = {}) { * after_render - Callback function to run after form is rendered * secondary - List of secondary modals to attach * callback - List of callback functions to attach to inputs + * focus - Select which field to focus on by default */ var modal = options.modal || '#modal-form'; @@ -763,6 +767,7 @@ function launchModalForm(url, options = {}) { modal: modal, submit_text: submit_text, close_text: close_text, + focus: options.focus }); }, success: function(response) { diff --git a/InvenTree/stock/templates/stock/item_tests.html b/InvenTree/stock/templates/stock/item_tests.html index 10bb0950e4..6bc120711d 100644 --- a/InvenTree/stock/templates/stock/item_tests.html +++ b/InvenTree/stock/templates/stock/item_tests.html @@ -73,6 +73,7 @@ $("#add-test-result").click(function() { stock_item: {{ item.id }}, }, success: reloadTable, + focus: 'test', } ); }); @@ -89,6 +90,7 @@ $("#test-result-table").on('click', '.button-test-add', function() { test: test_name }, success: reloadTable, + focus: 'value', } ); });