paper-input: Suggest values in typeahead

喜你入骨 提交于 2019-12-13 18:40:14

问题


Is there an easy way to implement a typeahead using Polymer's <paper-input> element? The HTML <datalist> tag seems to implement that for normal <input> tags and I could dynamically update the data list using templates.

However, this does nothing:

<paper-input
  label="Topic"
  list="dl">
</paper-input>
<datalist id="dl">
  <option>a</option>
  <option>aa</option>
  <option>aaa</option>
  <option>ab</option>
</datalist>

回答1:


Besides the fact you misuse options,

<datalist id="dl">
  <option value='a'></option>
  <!-- WRONG: <option>a</option> -->
</datalist>

I would suggest you to take a look into paper-input code and use paper-input-decorator with plain input as they do for paper-input:

<paper-input-decorator id="decorator">
  <input list="dl" is="core-input">
  <datalist id="dl">
    <option value='a'></option>
    <option value='ab'></option>
    <option value='ac'></option>
    <option value='ffa'></option>
  </datalist>
</paper-input-decorator>



回答2:


Polymer/paper-input has been deprecated, the currently supported version is PolymerElements/paper-input.

To use a datalist with paper-input in Polymer 1.0+:

<paper-input-container>
    <input list="choices" is="iron-input">
    <datalist id="choices">
        <option value='a'></option>
        <option value='ab'></option>
        <option value='ac'></option>
        <option value='ffa'></option>
    </datalist>
</paper-input-container>



回答3:


Vaadin Combo Box https://vaadin.com/elements/-/element/vaadin-combo-box is a good apache-2 licensed option for a typeahead that fits in with the paper elements.




回答4:


Checkout this element. It's an element has the typeahead function.

https://github.com/cheonhyangzhang/paper-typeahead-input

Here is the demo & doc page http://cheonhyangzhang.github.io/paper-typeahead-input/components/paper-typeahead-input/



来源:https://stackoverflow.com/questions/27981869/paper-input-suggest-values-in-typeahead

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