STOP Google Autofill/AutoComplete from ruining my form, Disable autofill on form

与世无争的帅哥 提交于 2021-01-28 08:00:59

问题


I have a form with an input field:

<input id="postalCode" placeholder="Postal Code* (A0A 0A0)" autocomplete="off">

I was using my own custom autocomplete here which google autofill COVERS and ruins the validation and user experience in my form.

I have tried changing the id to something random id="ASDf" and still google infers the field type by the validation or placeholder. I have tried the autocomplete="off" and "false". Neither do anything. On this page:

https://www.canadapost.ca/cpotools/apps/fpc/personal/findAnAddress?execution=e1s1

They have successfully disabled it somehow.

I have tried everything from this page:

Disabling Chrome Autofill

And nothing works.


回答1:


Ok this worked for me:

role="presentation" autocomplete="nope" 

tested on Chrome Version 64.0.3282.186 (Official Build) (64-bit).

I had to add both of those to each input in question. I also added to the form tag. For this specific version of Chrome the autofill is disabled. I am leaving this here because this is a real pain and ALL the up front solutions in other posts DO NOT work.




回答2:


Solution : Replace 'Name' with your #id.

  $('#Name').on('mouseup keyup', function () {
        var val = $('#Name').val();
        val = val.length;
        if (val === 0) {
            $('#Name').attr('autocomplete', 'on');
        }
        else {
            $('#Name').attr('autocomplete', 'new-password');
        }
    }).on('mousedown keydown', function () {
        var val = $('#Name').val();
        var length = val.length;
        if (!length) {
            $('#Name').attr('autocomplete', 'new-password');
        }
    })


来源:https://stackoverflow.com/questions/49415236/stop-google-autofill-autocomplete-from-ruining-my-form-disable-autofill-on-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!