Setting autocomplete off

When the browser offers suggested values that may not be relevant to the users of your app, it may be necessary to switch the ‘autocomplete’ setting off. This is common for address / phone / email fields where the browser will suggest past values (usually relevant for the current user) but they may be filling in a form about other business contacts (eg. entering vendor details).

 

There are a couple of tricks to keep in mind

  • The autocomplete value needs to be set to “new-password” (If this doesn’t work you can also try "one-time-code" or “off”)

  • The code needs to be run after the control is rendered (i.e. after the page has been opened)

This code will switch off the autocomplete for all the input fields on the screen (note the Timeout is to allow time for all the controls to have rendered):

 

setTimeout(function() {
let elements = document.getElementsByClassName("sapMInputBaseInner")
for (var i = 0; i < elements.length; i++) {
elements[i].autocomplete = "new-password";
}
}, 1500);

 

If you are just wanting to switch off a single field, you can do it like this:

getControl("inWizStep2_Street").getDomRef().getElementsByClassName("sapMInputBaseInner")[0].setAttribute("autocomplete","one-time-code");