如何在Safari的地址字段中禁用自动完成功能? [英] How to disable autocomplete in address fields for Safari?

查看:104
本文介绍了如何在Safari的地址字段中禁用自动完成功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,其中已实现了一个自动建议的下拉列表(通过jQueryUI),以便用户可以在我们的应用程序中搜索联系人并自动填写其信息.我想在表单上禁用自动完成功能,但是Safari(在macOS上)忽略了autocomplete="off".我已经在输入字段以及<form>标记中指定了自动完成功能.该表格用于朋友的实际邮寄地址,而Safari显示的是来自Contacts.app的匹配联系人...,但它在我的自动建议下拉列表上覆盖了一个下拉列表.如何强制Safari停止显示此下拉菜单?

I have a form where I've implemented an autosuggest dropdown (via jQueryUI) so that a user can search for a contact in our app and have their information auto-filled. I want autocomplete to be disabled on the form, but Safari (on macOS) is ignoring autocomplete="off". I have specified autocomplete to be off on the input fields, as well as in the <form> tag. This form is for a physical mailing address for a friend, and Safari is showing matching contacts from Contacts.app... but it is overlaying a dropdown on top of my autosuggest dropdown. How do I force Safari to stop showing this dropdown?

<form accept-charset="UTF-8" action="/listings/sailing/create_customized_card" autocomplete="off" class="new_greeting_card" id="new_greeting_card" method="post">
...
  <li>
    <input autocomplete="off" autocorrect="off" class="validate required" id="to_name" name="delivery[to_name]" placeholder="First &amp; last name" size="30" type="text" />
  </li>
  <li>
    <input autocomplete="off" autocorrect="off" class="validate required" id="to_address_street_1" name="to_address[street_1]" placeholder="Street 1" size="30" type="text" />
  </li>
  <li>
    <input autocomplete="off" autocorrect="off" id="to_address_street_2" name="to_address[street_2]" size="30" type="text" />
  </li>
  <li>
    <input autocomplete="off" class="validate required city" id="to_address_city" name="to_address[city]" placeholder="City" size="30" type="text" />
    <select class="validate required state" id="to_address_state" name="to_address[state]">
    <option value="AK">AK</option>
    ...
    </select>
    <input autocomplete="off" class="validate required zip" id="to_address_zip_code" name="to_address[zip_code]" pattern="(\d{5}([\-]\d{4})?)" placeholder="Zip" size="30" type="text" />
  </li>
...
</form>

仅供参考-我知道大多数浏览器都会忽略autocomplete="off"的用户名和密码字段,但这是联系人的地址字段.

FYI - I know that most browsers ignore autocomplete="off" for username and password fields, but these are address fields for a contact.

推荐答案

似乎您无法以类似方式禁用自动完成功能. Safari在元素的id中查找某些关键字,如果存在诸如名称",地址",电子邮件"等之类的内容,它将启用自动完成功能(在Safari 10.1.1上进行了测试). br> 因此,我发现的唯一简单的解决方法是使用不会触发自动完成功能的其他id.

It seems you can't disable autocomplete in a similar way. Safari looks for certain keywords in the id of the element and if there is something like "name", "address", "e-mail" etc., it enables the autocomplete function (tested on Safari 10.1.1).
So, the only simple workaround that I've found is to use a different id that doesn't trigger the autocomplete function.

我发现Safari也使用placeholder属性来确定是否启用自动完成功能.

I found out that Safari also uses the placeholder attribute to determine whether to enable autocomplete function or not.

这篇关于如何在Safari的地址字段中禁用自动完成功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆