Giter Club home page Giter Club logo

bootstrap-5-autocomplete's Introduction

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'},
]);

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 has to be an array of JSON objects. The format for every item in the array is:

{"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:
Wether to highlight (style) typed text on items. Default is true.

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

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

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

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

License

MIT

bootstrap-5-autocomplete's People

Contributors

cbke avatar gch1p avatar lukasjelonek avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.