material-ui TextField禁用浏览器自动完成

问题描述 投票:4回答:5

我使用材料ui v0.20.0并且我必须禁止为具有TextField的用户保存密码。我添加了道具到TextField autocomplete ='nope',因为并非所有的浏览器都能理解autocomplete ='off'。似乎Chrome 63的最新版本不接受它。有时候它不起作用,有时也会起作用。我无法理解为什么它如此繁忙。当chrome要求保存密码并保存时,之后我想编辑输入我仍然有这个:enter image description here

  <TextField
         name='userName'
         floatingLabelText={<FormattedMessage id='users.username' />}
         value={name || ''}
         onChange={(e, name) => this.changeUser({name})}
         // autoComplete='new-password'

    /> 

    <TextField
        name='password'
        floatingLabelText={<FormattedMessage id='users.passwords.new' />}
        type='password'
        value={password || ''}
        onChange={(e, password) => this.changeUser({password})}
        autoComplete='new-password'
   />

看起来它适用于Firefox(v57.0.4)

默认情况下,TextField没有autoComplete ='off'enter image description here

html forms input autocomplete material-ui
5个回答
2
投票

这似乎对我有用(我们使用带有redux形式的材料ui)

 <Textfield
    inputProps={
    {
      autocomplete: "new-password",
      form: {
        autocomplete: "off",
      }
    }
  />

如果输入是type =“password”off,则“new-password”有效“如果它是一个包含在表单中的常规文本字段,则可以正常工作


1
投票

固定。只需要添加上面的实际输入字段

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion - MDN https://medium.com/paul-jaworski/turning-off-autocomplete-in-chrome-ee3ff8ef0908 - 在EDGE,Chrome(最新版本v63),Firefox Quantum(57.0.4 64-бит),Firefox(52.2.0)虚拟字段上进行中等测试假冒字段是Chrome / opera自动填充错误字段的解决方法

 const fakeInputStyle = {opacity: 0, float: 'left', border: 'none', height: '0', width: '0'}

 <input type="password" name='fake-password' autoComplete='new-password' tabIndex='-1' style={fakeInputSyle} />

  <TextField
  name='userName'
  autoComplete='nope'
  ... 
/>

<TextField
      name='password'
      autoComplete='new-password'
      ... 
    />

1
投票

在材料-ui TextField中禁用自动完成。它适合我

<TextField
  name='password'
  autoComplete='off'
  type='text'
  ... 
/>

应该是autoComplete ='off'

autoComplete='off'

0
投票

您不再需要为主分支上的AutoComplete组件提供autoComplete ='off'。它是默认添加的。

查看this thread了解更多详情。


0
投票

这对我有用:

每当您想要为密码字段(也是上面的字段)禁用自动填充时,只需将其放入密码输入中:

<input type="password" name='any-filed-name-here-password' autoComplete='new-password' />

重要的是拥有autoComplete='new-password'

© www.soinside.com 2019 - 2024. All rights reserved.