MDL-85774 login: Check for username/password fields before moving focus
When the login form is not shown but $CFG->loginautofocus is turned on, we need to verify first that the username and password fields exist before we move the focus. Otherwise, the JS will break.
This commit is contained in:
@@ -219,10 +219,11 @@
|
||||
require(['core_form/events'], function(FormEvent) {
|
||||
function autoFocus() {
|
||||
const userNameField = document.getElementById('username');
|
||||
if (userNameField.value.length == 0) {
|
||||
const passwordField = document.getElementById('password');
|
||||
if (userNameField && userNameField.value.length == 0) {
|
||||
userNameField.focus();
|
||||
} else {
|
||||
document.getElementById('password').focus();
|
||||
} else if (passwordField) {
|
||||
passwordField.focus();
|
||||
}
|
||||
}
|
||||
autoFocus();
|
||||
|
||||
Reference in New Issue
Block a user