Pixabay JavaScript Autocomplete

1.0.4 · abandoned · verified Sun Apr 19

This package provides a lightweight, vanilla JavaScript solution for autocomplete and autosuggest functionalities. Released in 2015, its current stable version is 1.0.4, last updated in February 2016. It distinguishes itself by having no external dependencies, a small footprint (less than 2.4 KB gzipped), and extensive browser support down to Internet Explorer 8+. It was developed by Pixabay.com and features a flexible data source, smart caching, configurable delay, and minimum character settings. Its release cadence was short-lived, with the last update nearly a decade ago, indicating it is no longer actively maintained. While functional for its intended environment, it lacks modern JavaScript ecosystem integrations.

Common errors

Warnings

Install

Imports

Quickstart

This HTML example demonstrates how to include the `autocomplete.min.js` script and initialize the `autoComplete` constructor on an input field with a static data source.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Autocomplete Demo</title>
    <!-- Assuming autocomplete.min.js is in the same directory -->
    <script src="autocomplete.min.js"></script>
    <style>
        .autocomplete-suggestions {
            border: 1px solid #999;
            background: #FFF;
            overflow: auto;
            max-height: 150px;
        }
        .autocomplete-suggestion {
            padding: 2px 5px;
            white-space: nowrap;
            overflow: hidden;
            cursor: pointer;
        }
        .autocomplete-selected {
            background: #F0F0F0;
        }
        .autocomplete-suggestions strong {
            font-weight: normal;
            color: #3399FF;
        }
    </style>
</head>
<body>
    <h1>Search for fruits:</h1>
    <input type="text" id="my-input" placeholder="Start typing...">

    <script>
        new autoComplete({
            selector: '#my-input',
            minChars: 1,
            source: function(term, suggest){
                term = term.toLowerCase();
                const choices = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry', 'Fig', 'Grape', 'Honeydew', 'Kiwi', 'Lemon', 'Mango', 'Nectarine', 'Orange', 'Papaya', 'Quince', 'Raspberry', 'Strawberry', 'Tangerine', 'Ugli Fruit', 'Vanilla Bean', 'Watermelon', 'Xigua', 'Yellow Passion Fruit', 'Zucchini'];
                const matches = [];
                for (let i=0; i<choices.length; i++)
                    if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]);
                suggest(matches);
            }
        });
    </script>
</body>
</html>

view raw JSON →