Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome ignores autocomplete="off" for select2

Tried several methods of disabling autocomplete and Chrome still ignores it when using jQuery Select2 input.

I tried inserting another input field (and using display: none) before the real input to try to trick Chrome, this didn't seem to work either.

Here is how the input looks now:

<input type="text" autocomplete="off" autocorrect="off" 
autocapitalize="off" spellcheck="false" class="select2-input select2-default" id="s2id_autogen2" placeholder="" style="width: 283px;" aria-activedescendant="select2-result-label-3">

When clicking on the field, at least half the time Chrome will try to autocomplete it with my phone numbers saved in Chrome. Any ideas how to disable it? It also inhibits the Select2 use as it covers it's options up.

like image 485
kevmor Avatar asked Jun 27 '19 16:06

kevmor


People also ask

Does Chrome ignore autocomplete off?

Chrome intentionally ignores autocomplete=“off” and autocomplete=“false”. However, they put new-password in as a special clause to stop new password forms from being auto-filled.

Do browsers respect autocomplete off?

Chrome respects autocomplete=off only when there is at least one other input element in the form with any other autocomplete value. This will not work with password fields--those are handled very differently in Chrome.


2 Answers

It's Simple try it

<script type="text/javascript" charset="UTF-8">
$(document).ready(function(){
    $( document ).on( 'focus', ':input', function(){
        $( this ).attr( 'autocomplete', 'new-password' );
    }); 
    $( "input.select2-input" ).attr( 'autocomplete', 'new-password' );

});
</script>
like image 133
Eng Acs Avatar answered Sep 26 '22 06:09

Eng Acs


Simply wrap your input in <form autocomplete="off">

<form autocomplete="off">
    <input type="text" ...>
</form>
like image 23
Zw1d Avatar answered Sep 23 '22 06:09

Zw1d