|
115 | 115 | </div> |
116 | 116 | {{/maintenance}} |
117 | 117 | {{#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> |
120 | 119 | {{/error}} |
121 | 120 | {{#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> |
124 | 122 | {{/info}} |
125 | | - {{#cansignup}} |
126 | | - <a href="{{signupurl}}" class="sr-only">{{#str}} tocreatenewaccount {{/str}}</a> |
127 | | - {{/cansignup}} |
128 | 123 | {{#showloginform}} |
129 | 124 | <form class="login-form" action="{{loginurl}}" method="post" id="login"> |
130 | 125 | <input id="anchor" type="hidden" name="anchor" value=""> |
|
224 | 219 | require(['core_form/events'], function(FormEvent) { |
225 | 220 | function autoFocus() { |
226 | 221 | const userNameField = document.getElementById('username'); |
227 | | - if (userNameField.value.length == 0) { |
| 222 | + const passwordField = document.getElementById('password'); |
| 223 | + if (userNameField && userNameField.value.length == 0) { |
228 | 224 | userNameField.focus(); |
229 | | - } else { |
230 | | - document.getElementById('password').focus(); |
| 225 | + } else if (passwordField) { |
| 226 | + passwordField.focus(); |
231 | 227 | } |
232 | 228 | } |
233 | 229 | autoFocus(); |
234 | 230 | window.addEventListener(FormEvent.eventTypes.fieldStructureChanged, autoFocus); |
235 | 231 | }); |
236 | 232 | {{/autofocusform}} |
237 | 233 | {{/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 += " "; |
| 250 | + } |
| 251 | + if (infoMessage) { |
| 252 | + infoMessageDiv.innerHTML += " "; |
| 253 | + } |
| 254 | + pendingJS.resolve(); |
| 255 | + }, 500); |
| 256 | + } |
| 257 | + }); |
241 | 258 | {{#togglepassword}} |
242 | 259 | require(['core/togglesensitive'], function(ToggleSensitive) { |
243 | 260 | ToggleSensitive.init("password", {{smallscreensonly}}); |
|
0 commit comments