Autocomplete / Autofill with Polymer input element

2019-07-04 17:10发布

问题:

I'm having an issue getting Chrome's autofill and/or autocomplete working with Polymer input elements, such as gold-email-input. I've tried setting the autocomplete attribute of the gold-email-input component to on and I've also tried setting it to email. The autofill box appears, but selecting an entry from the autofill selections does not populate the control. What am I doing wrong?

回答1:

<form is="iron-form">
  <gold-email-input></gold-email-input>
</form>

This tends to work



回答2:

You don't need to set the autocomplete attribute, as it's already set to autocomplete=email.

I think we need to see a sample of your code in context because the input automatically populates for me when I select the autofill suggestion:

jsbin



回答3:

Try wrapping your input elements in a form element. This works for me:

<form>
     <paper-input id="user"
                   autocomplete="email"
                   label="Username or email"
                   value="{{user}}"
      </paper-input>
      <paper-input id="pwd"
                   autocomplete="current-password"
                   label="Password"
                   value="{{pwd}}"
      </paper-input>
</form>