Merge pull request #946 from SchrodingersGat/field-focus

Add "focus" option when displaying a modal form
This commit is contained in:
Oliver 2020-09-01 13:04:02 +10:00 committed by GitHub
commit c3c5a86ea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -469,6 +469,9 @@ function openModal(options) {
$(modal).on('shown.bs.modal', function() { $(modal).on('shown.bs.modal', function() {
$(modal + ' .modal-form-content').scrollTop(0); $(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 // 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 * after_render - Callback function to run after form is rendered
* secondary - List of secondary modals to attach * secondary - List of secondary modals to attach
* callback - List of callback functions to attach to inputs * callback - List of callback functions to attach to inputs
* focus - Select which field to focus on by default
*/ */
var modal = options.modal || '#modal-form'; var modal = options.modal || '#modal-form';
@ -763,6 +767,7 @@ function launchModalForm(url, options = {}) {
modal: modal, modal: modal,
submit_text: submit_text, submit_text: submit_text,
close_text: close_text, close_text: close_text,
focus: options.focus
}); });
}, },
success: function(response) { success: function(response) {

View File

@ -73,6 +73,7 @@ $("#add-test-result").click(function() {
stock_item: {{ item.id }}, stock_item: {{ item.id }},
}, },
success: reloadTable, success: reloadTable,
focus: 'test',
} }
); );
}); });
@ -89,6 +90,7 @@ $("#test-result-table").on('click', '.button-test-add', function() {
test: test_name test: test_name
}, },
success: reloadTable, success: reloadTable,
focus: 'value',
} }
); );
}); });