Focus the primary button in confirmation dialogs so Enter confirms
Confirmation dialogs opened with showModalDialog() leave focus on the modal container, so Enter does nothing and Tab starts from the close button. Focus the primary button after the dialog body is inserted. Dialogs with a field to fill in (such as Delete User, which asks to type DELETE) are left as they are.
This commit is contained in:
13
public/js/main.js
vendored
13
public/js/main.js
vendored
@@ -3598,6 +3598,19 @@ function showModalDialog(body, options)
|
||||
}
|
||||
options = Object.assign(standard_options, options);
|
||||
|
||||
// Focus the primary button, so Enter confirms and Tab moves to Cancel.
|
||||
// Skipped when the dialog has a field to fill in.
|
||||
var on_show = options.on_show;
|
||||
options.on_show = function(modal, a) {
|
||||
if (typeof(on_show) == "function") {
|
||||
on_show(modal, a);
|
||||
}
|
||||
var modal_body = modal.children().find('.modal-body:first');
|
||||
if (!modal_body.find('input:visible,textarea:visible,select:visible').length) {
|
||||
modal_body.find('.btn-primary:enabled:visible:first').focus();
|
||||
}
|
||||
};
|
||||
|
||||
triggerModal(null, options);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user