substack / Autocomplete Element
Licence: other
autocomplete for an `<input type="text">` element
Stars: ✭ 68
Programming Languages
javascript
184084 projects - #8 most used programming language
autocomplete-element
Wire up autocomplete for an <input type="text">
element.
example
Auto-complete the months.
var auto = require('autocomplete-element');
var input = document.querySelector('input');
var months = [
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"
];
auto(input, function (c) {
if (!input.value.length) return c.suggest([]);
var matches = months.filter(function (m) {
return lc(m.slice(0, input.value.length)) === lc(input.value);
});
c.suggest(matches);
});
function lc (x) { return x.toLowerCase() }
methods
var c = auto(input, fn)
Create a new autocomplete instance c
that wraps an input
element and
optionally sets up a keydown listener fn
.
fn(c, ev)
fires when there is new text input to deal with.
c.suggest(suggestions)
Auto-complete an array of suggestions
. The first suggestion in the array is
shadowed under the active text.
c.set(value)
Set the value for the input text and the shadow text.
install
With npm do:
npm install autocomplete-element
license
MIT
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].