JavaScript AutoComplete Library

1.0.5 · abandoned · verified Sun Apr 19

JavaScript-autoComplete is an extremely lightweight and powerful vanilla JavaScript completion suggester. Developed by Pixabay.com, it provides flexible data sourcing, smart caching, and callback functionalities with no external dependencies. The library is very small, weighing in at less than 2.4 kB gzipped. It was last updated in 2016, with its current stable version being 1.0.5. Given its age and lack of recent development, it operates on a very slow release cadence and is primarily intended for environments where a minimal, standalone JavaScript solution is preferred over modern, framework-integrated alternatives. Key differentiators include its zero-dependency nature and extreme lightness, making it suitable for legacy projects or very simple, performance-critical contexts where a full-featured library would be overkill.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `AutoComplete` library on an input field using a static array as the data source and logs the selected item to the console.

<html>
<head>
  <title>JavaScript AutoComplete Demo</title>
  <style>
    .autocomplete-suggestions {
      border: 1px solid #999;
      background: #FFF;
      overflow: auto;
      max-height: 200px;
      position: absolute;
      z-index: 9999;
    }
    .autocomplete-suggestion {
      padding: 2px 5px;
      white-space: nowrap;
      overflow: hidden;
    }
    .autocomplete-selected {
      background: #F0F0F0;
    }
    .autocomplete-suggestions strong {
      font-weight: normal;
      color: #3399FF;
    }
  </style>
</head>
<body>
  <h1>Search Programming Languages</h1>
  <input type="text" id="search-field" placeholder="Type a language...">

  <script src="https://goodies.pixabay.com/javascript/auto-complete/auto-complete.min.js"></script>
  <script>
    const languages = [
      'ActionScript', 'AppleScript', 'Asp', 'BASIC', 'C', 'C++', 'Clojure', 'CSS', 'Erlang', 
      'Go', 'Groovy', 'Haskell', 'HTML', 'Java', 'JavaScript', 'Lisp', 'Perl', 'PHP', 
      'Python', 'Ruby', 'Scala', 'Scheme', 'Swift', 'TypeScript', 'Rust', 'Kotlin'
    ];

    new AutoComplete({
      selector: '#search-field',
      minChars: 1,
      delay: 150,
      source: function(term, suggest){
        term = term.toLowerCase();
        const suggestions = languages.filter(lang => lang.toLowerCase().includes(term));
        suggest(suggestions);
      },
      onSelect: function(event, term, item){
        console.log('Selected:', term);
        // Optionally do something with the selected term, e.g., navigate or update other fields
      }
    });
  </script>
</body>
</html>

view raw JSON →