From e972b7629cd1c2948e664b6b6d737c6696ec197e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 3 Sep 2017 11:39:47 +0200 Subject: [PATCH] Set focus on first visible input when modal is shown issue6684 review35531002 --- CHANGELOG | 1 + src/sao.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 5ceaa8c9c1..17231b5b13 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Set focus on first visible input when modal is shown * Improve treeview headers * Add keyboard shortcuts * Update states of both toolbar and menu diff --git a/src/sao.js b/src/sao.js index d540c24b3f..b7f8ba5e1d 100644 --- a/src/sao.js +++ b/src/sao.js @@ -516,6 +516,14 @@ var Sao = {}; this.footer = jQuery('
', { 'class': 'modal-footer' }).appendTo(this.content); + + this.modal.on('shown.bs.modal', function() { + var currently_focused = jQuery(document.activeElement); + var has_focus = currently_focused.closest(this.el) > 0; + if (!has_focus) { + jQuery(this).find(':input:visible:first').focus(); + } + }); }, add_title: function(title) { this.header.append(jQuery('

', {