Chrome warning "[DOM] Password forms should have (optionally hidden) username fields for accessibility" in console even with hidden username field

arne.b picture arne.b · Jan 30, 2018 · Viewed 14.7k times · Source

When visiting the "reset password" route of my single-page app and looking at the Chrome browser console, I am greeted with the follwing warning:

[DOM] Password forms should have (optionally hidden) username fields for accessibility: (More info: goo.gl/9p2vKq)

Helpfully, the html of the form in question is also printed to the console in the next line, and quite clearly contains a hidden username field:

<form data-ember-action data-ember-action-436=​"436">​
  <div class=​"form-group">
    ​<label for=​"newpasswordone">​Password​</label>​
    <input type=​"password" autocomplete=​"new-password" placeholder=​"Enter your new password" id=​"ember437" class=​"form-control ember-text-field ember-view" data-op-id=​"0">​

    <label for=​"newpasswordtwo">​Password (again)​</label>
    ​<input type=​"password" autocomplete=​"new-password" placeholder=​"Re-enter your new password" id=​"ember438" class=​"form-control ember-text-field ember-view" data-op-id=​"1">​
    <input type=​"hidden" name=​"username" autocomplete=​"username" value=​"a_b">
​  </div>​
  <button disabled type=​"submit" class=​"btn btn-default">​Reset password​</button>​​
</form>​

I tried some minor variations -- unhiding the username field, marking it readonly, moving it outside the div -- without affecting the warning. How does Chrome expect to be served the username?

Problem occurs with Chrome 63 and 64.

Answer

Jonas Hungershausen picture Jonas Hungershausen · Feb 11, 2018

I had the same problem. After some digging, I found that it needs to be an input element with the type text. By "optionally hidden" they mean that you may hide it with CSS.

If you just add an input with the name email or username chrome gives you another warning saying that input elements should have autocomplete attributes. So this is what I came up with to fix these errors:

<input type="text" name="email" value="..." autocomplete="username email" style="display: none;">.

You will need to manually render the actual username or email into the elements value attribute.

Also, keep in mind that inline styles are not a very good practice.