npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

autocomplete-bs5

v1.0.0

Published

This is a rewrite of https://github.com/Honatas/bootstrap-4-autocomplete for bootstrap v5.

Downloads

6

Readme

bootstrap-5-autocomplete

This is a rewrite of https://github.com/Honatas/bootstrap-4-autocomplete for bootstrap v5.

Example

const ac = new Autocomplete(field, {
    data: [{label: "I'm a label", value: 42}],
    maximumItems: 5,
    onSelectItem: ({label, value}) => {
        console.log("user selected:", label, value);
    }
});

// later, when you need to change the dataset

ac.setData([
    {label: 'New York JFK', value: 'JFK'},
    {label: 'Moscow SVO', value: 'SVO'},
]);

Or use custom label/value keys:

const ac = new Autocomplete(field, {
    data: [{name: "entry1", text: "The first entry"}, {name: "entry2", text: "The second entry"}],
    label: "name",
    value: "text",
    onSelectItem: ({label, value}) => {
        console.log("user selected:", label, value);
    }
});

Or use a simple object instead of an array of objects:

const ac = new Autocomplete(field, {
    data: {entry1: "The first entry", entry2: "The second entry"},
    label: null,
    value: null,
    onSelectItem: ({label, value}) => {
        console.log("user selected:", label, value);
    }
});

Options

Options is a JSON object with the following attributes (in alphabetical order):

data:
The data from where autocomplete will lookup items to show. This data can be a simple object or an array of JSON objects. By default the format for every object in the array is as following, but you can also change the name of the label and value keys (see below):

{"label": "This is a text", "value": 42}

dropdownOptions:
It's the same options from Bootstrap's Dropdown, documented here.

dropdownClass:
The class of the dropdown-menu element, which is the box that is displayed. Can take a string or an array of strings.

highlightClass:
The class to use when highlighting typed text on items. Only used when highlightTyped is true. Default is text-primary. Can take a string or an array of strings.

highlightTyped:
Whether to highlight (style) typed text on items. Default is true.

label:
The name of the label key in your data. The label is what will be shown on each item in the autocomplete list.

maximumItems:
How many items you want to show when the autocomplete is displayed. Default is 5. Set to 0 to display all available items.

onInput:
A callback function to execute on user input.

onSelectItem:
A callback that is fired every time an item is selected. It receives an object in following format:

{label: <label>, value: <value>}

showValue:
If set to true, will display the value of the entry after the label in the dropdown list.

showValueBeforeLabel:
If set to true and showValue also set to true, the value will be displayed before the label.

threshold:
The number of characters that need to be typed on the input in order to trigger the autocomplete. Default is 4.

value:
The name of the value key in your data.

License

MIT