Skip to content

Commit 63aa786

Browse files
committed
Upstream change: Adopt changes from MDL-85774 into loginform.mustache, resolves #1093 (#1094)
1 parent 9b5cf01 commit 63aa786

File tree

3 files changed

+61
-26
lines changed

3 files changed

+61
-26
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changes
66

77
### Unreleased
88

9+
* 2025-11-07 - Upstream change: Adopt changes from MDL-85774 into loginform.mustache, resolves #1093
910
* 2025-11-04 - Bugfix: When upgrading a Boost Union installation from the ancient pre-smart-menu-era to a recent version, Boost Union tried to access a table which does not exist yet, resolves #1085
1011
* 2025-11-03 - Glitch: upgrade.php did not match install.xml regarding the theme_boost_union_snippets table, resolves #1062
1112
* 2025-11-03 - Improvement: Use human-understandable values in the background position settings, resolves #1086

templates/core/loginform.mustache

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,11 @@
132132
</div>
133133
{{/maintenance}}
134134
{{#error}}
135-
<a href="#" id="loginerrormessage" class="sr-only">{{error}}</a>
136-
<div class="alert alert-danger" role="alert">{{error}}</div>
135+
<div class="alert alert-danger" id="loginerrormessage" role="alert">{{error}}</div>
137136
{{/error}}
138137
{{#info}}
139-
<a href="#" id="logininfomessage" class="sr-only">{{info}}</a>
140-
<div class="alert alert-info" role="alert">{{info}}</div>
138+
<div class="alert alert-info" id="logininfomessage" role="status">{{info}}</div>
141139
{{/info}}
142-
{{#cansignup}}
143-
<a href="{{signupurl}}" class="sr-only">{{#str}} tocreatenewaccount {{/str}}</a>
144-
{{/cansignup}}
145140
<div id="theme_boost_union-loginorder">
146141
{{#showlocallogin}}
147142
<div id="theme_boost_union-loginorder-local" class="theme_boost_union-loginmethod">
@@ -257,20 +252,42 @@
257252
require(['core_form/events'], function(FormEvent) {
258253
function autoFocus() {
259254
const userNameField = document.getElementById('username');
260-
if (userNameField.value.length == 0) {
255+
const passwordField = document.getElementById('password');
256+
if (userNameField && userNameField.value.length == 0) {
261257
userNameField.focus();
262-
} else {
263-
document.getElementById('password').focus();
258+
} else if (passwordField) {
259+
passwordField.focus();
264260
}
265261
}
266262
autoFocus();
267263
window.addEventListener(FormEvent.eventTypes.fieldStructureChanged, autoFocus);
268264
});
269265
{{/autofocusform}}
270266
{{/error}}
271-
{{#error}}
272-
document.getElementById('loginerrormessage').focus();
273-
{{/error}}
267+
require(['core/pending'], function(Pending) {
268+
const errorMessageDiv = document.getElementById('loginerrormessage');
269+
const infoMessageDiv = document.getElementById('logininfomessage');
270+
const errorMessage = errorMessageDiv?.textContent.trim();
271+
const infoMessage = infoMessageDiv?.textContent.trim();
272+
if (errorMessage || infoMessage) {
273+
const pendingJS = new Pending('login-move-focus');
274+
const usernameField = document.getElementById('username');
275+
setTimeout(function() {
276+
// Focus on the username field on error.
277+
if (errorMessage && usernameField) {
278+
usernameField.focus();
279+
}
280+
// Append a non-breaking space to the error/status message so screen readers will announce them after page load.
281+
if (errorMessage) {
282+
errorMessageDiv.innerHTML += "&nbsp;";
283+
}
284+
if (infoMessage) {
285+
infoMessageDiv.innerHTML += "&nbsp;";
286+
}
287+
pendingJS.resolve();
288+
}, 500);
289+
}
290+
});
274291
{{#togglepassword}}
275292
require(['core/togglesensitive'], function(ToggleSensitive) {
276293
ToggleSensitive.init("password", {{smallscreensonly}});

templates/core/loginform.mustache.upstream

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,11 @@
115115
</div>
116116
{{/maintenance}}
117117
{{#error}}
118-
<a href="#" id="loginerrormessage" class="sr-only">{{error}}</a>
119-
<div class="alert alert-danger" role="alert">{{error}}</div>
118+
<div class="alert alert-danger" id="loginerrormessage" role="alert">{{error}}</div>
120119
{{/error}}
121120
{{#info}}
122-
<a href="#" id="logininfomessage" class="sr-only">{{info}}</a>
123-
<div class="alert alert-info" role="alert">{{info}}</div>
121+
<div class="alert alert-info" id="logininfomessage" role="status">{{info}}</div>
124122
{{/info}}
125-
{{#cansignup}}
126-
<a href="{{signupurl}}" class="sr-only">{{#str}} tocreatenewaccount {{/str}}</a>
127-
{{/cansignup}}
128123
{{#showloginform}}
129124
<form class="login-form" action="{{loginurl}}" method="post" id="login">
130125
<input id="anchor" type="hidden" name="anchor" value="">
@@ -224,20 +219,42 @@
224219
require(['core_form/events'], function(FormEvent) {
225220
function autoFocus() {
226221
const userNameField = document.getElementById('username');
227-
if (userNameField.value.length == 0) {
222+
const passwordField = document.getElementById('password');
223+
if (userNameField && userNameField.value.length == 0) {
228224
userNameField.focus();
229-
} else {
230-
document.getElementById('password').focus();
225+
} else if (passwordField) {
226+
passwordField.focus();
231227
}
232228
}
233229
autoFocus();
234230
window.addEventListener(FormEvent.eventTypes.fieldStructureChanged, autoFocus);
235231
});
236232
{{/autofocusform}}
237233
{{/error}}
238-
{{#error}}
239-
document.getElementById('loginerrormessage').focus();
240-
{{/error}}
234+
require(['core/pending'], function(Pending) {
235+
const errorMessageDiv = document.getElementById('loginerrormessage');
236+
const infoMessageDiv = document.getElementById('logininfomessage');
237+
const errorMessage = errorMessageDiv?.textContent.trim();
238+
const infoMessage = infoMessageDiv?.textContent.trim();
239+
if (errorMessage || infoMessage) {
240+
const pendingJS = new Pending('login-move-focus');
241+
const usernameField = document.getElementById('username');
242+
setTimeout(function() {
243+
// Focus on the username field on error.
244+
if (errorMessage && usernameField) {
245+
usernameField.focus();
246+
}
247+
// Append a non-breaking space to the error/status message so screen readers will announce them after page load.
248+
if (errorMessage) {
249+
errorMessageDiv.innerHTML += "&nbsp;";
250+
}
251+
if (infoMessage) {
252+
infoMessageDiv.innerHTML += "&nbsp;";
253+
}
254+
pendingJS.resolve();
255+
}, 500);
256+
}
257+
});
241258
{{#togglepassword}}
242259
require(['core/togglesensitive'], function(ToggleSensitive) {
243260
ToggleSensitive.init("password", {{smallscreensonly}});

0 commit comments

Comments
 (0)