diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 6572ecdc4b3..3c0d900408b 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -854,6 +854,16 @@ M.util.focus_login_form = function(Y) { } } +/** + * Set focus on login error message + */ +M.util.focus_login_error = function(Y) { + var errorlog = Y.one('#errormsg'); + + if (errorlog) { + errorlog.focus(); + } +} /** * Adds lightbox hidden element that covers the whole node. * diff --git a/login/index.php b/login/index.php index 6276a578993..31d3a013b4f 100644 --- a/login/index.php +++ b/login/index.php @@ -345,7 +345,9 @@ if (isloggedin() and !isguestuser()) { echo $OUTPUT->box_end(); } else { include("index_form.html"); - if (!empty($CFG->loginpageautofocus)) { + if ($errormsg) { + $PAGE->requires->js_init_call('M.util.focus_login_error', null, true); + } else if (!empty($CFG->loginpageautofocus)) { //focus username or password $PAGE->requires->js_init_call('M.util.focus_login_form', null, true); } diff --git a/login/index_form.html b/login/index_form.html index 5c9f34dfebe..8ec496cb645 100644 --- a/login/index_form.html +++ b/login/index_form.html @@ -31,6 +31,7 @@ if (!empty($CFG->loginpasswordautocomplete)) { '; + echo ''.$OUTPUT->error_text($errormsg).''; echo $OUTPUT->error_text($errormsg); echo ''; }