Home Forums Backend Issues (wp-admin) Text field: Disable browser's autocomplete


Text field: Disable browser's autocomplete

  • Hi there,

    is there a way (via filters etc.) to disable the browser’s autocomplete functionality for text fields. Basically to add autocomplete="off" to the <input>?


  • Currently, the only way that I can see this might be done is by adding custom JavaScript to the page to turn on autocomplete on some fields after the page loads. I’m not 100% sure how you’d do that.

    This is only a guess:

    jQuery(document).ready($) {
      // the field key of your field
      $('[data-key="field_1234567"] input').attr('autocomplete', 'off');
  • This has bothered me too, especially in Chrome, because most places you would a password field are not something that would autofill for the site (login, etc). Chrome will automatically try to fill in the password, which removes the existing value. This creates a situation where you can’t save the existing password without disabling autofill in the browser.

    To overcome this, here is a quick patch you can put in your functions.php file.

    add_action( 'acf/render_field/type=password', function(){
    }, 8);
    add_action( 'acf/render_field/type=password', function(){
       return str_replace( '<input ', '<input autocomplete="new-password" ', ob_get_clean() );
    }, 10);

    I think this attribute should be part of the core password field to avoid the situation described above as it is one that I run into with a lot of my clients.


  • John’s jQuery wasn’t far off.

    jQuery(document).ready( function($) {
    	$('[data-key="field_1234567"] input').attr('autocomplete', 'off');

    Either save it as a js file and enqueue it on the relevant pages, or enclose it in <script type=”text/javascript”></script> and add it to the relevant page’s footer

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Text field: Disable browser's autocomplete’ is closed to new replies.