项目作者: yuwui

项目描述 :
Zero dependency HTML input autocompletion library
高级语言: JavaScript
项目地址: git://github.com/yuwui/Compleet.git
创建时间: 2018-03-31T19:42:18Z
项目社区:https://github.com/yuwui/Compleet

开源协议:GNU Lesser General Public License v3.0

下载


Compleet

Zero dependency JavaScript autocompletion library.

Why

Because there weren’t any other libraries that did what I needed.

Usage

  1. const input = document.querySelector("input#myinput");
  2. input.compleet({
  3. // OR
  4. compleet(input, {
  5. // General options
  6. maxResults: 10, // max results, default is 5
  7. raw: false, // whether to use innerHTML or innerText to set autocomplete options, default is false (innerText)
  8. // ^^^^^ DO NOT SET THIS TO TRUE IF YOU PROVIDE UNFILTERED USER TAGS, YOU HAVE BEEN WARNED
  9. // Tag source options
  10. source: function(term, resp) {
  11. const val = term.split(" ").pop(); // split the value by spaces
  12. const terms = getTermsFromSomewhere(); // get the terms from somewhere
  13. const matched = terms.filter(function(t) { return t.startsWith(val); }); // filter the terms
  14. resp(matched, val); // send the response
  15. },
  16. // OR
  17. tags: function(resp) {
  18. getTermsFromSomewhere(function(terms) { resp(terms); });
  19. }
  20. });

Contributing

PRs are always welcome!