na-2n / Compleet

Zero dependency HTML input autocompletion library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compleet

Zero dependency JavaScript autocompletion library.

Why

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

Usage

const input = document.querySelector("input#myinput");

input.compleet({
// OR
compleet(input, {
    // General options
    maxResults: 10, // max results, default is 5
    raw: false, // whether to use innerHTML or innerText to set autocomplete options, default is false (innerText)
    //   ^^^^^ DO NOT SET THIS TO TRUE IF YOU PROVIDE UNFILTERED USER TAGS, YOU HAVE BEEN WARNED

    // Tag source options
    source: function(term, resp) {
        const val = term.split(" ").pop(); // split the value by spaces
        const terms = getTermsFromSomewhere(); // get the terms from somewhere
        const matched = terms.filter(function(t) { return t.startsWith(val); }); // filter the terms

        resp(matched, val); // send the response
    },
    // OR
    tags: function(resp) {
        getTermsFromSomewhere(function(terms) { resp(terms); });
    }
});

Contributing

PRs are always welcome!

About

Zero dependency HTML input autocompletion library

License:GNU Lesser General Public License v3.0


Languages

Language:JavaScript 63.0%Language:HTML 27.6%Language:CSS 9.4%