Giter Site home page Giter Site logo

Comments (5)

LuViKu avatar LuViKu commented on June 7, 2024 2

Hey I encountered the same problem. I think according to the documentation you could implement a custom search engine. For me setting the search engine to "loose" solved my problem.

EDIT:
It turns out building a custom search engine is easier than I thought.
function searchEngine(query, record) { return record;} This directly returns all the results you receive from your REST API call. The only this is, that the parts of the result matching the query string are not highlighted anymore.

from autocomplete.js.

adamtheapiguy avatar adamtheapiguy commented on June 7, 2024

Thank you @LuViKu

from autocomplete.js.

squareclouds avatar squareclouds commented on June 7, 2024

@LuViKu can you please give an example of the whole config or setup?

from autocomplete.js.

LuViKu avatar LuViKu commented on June 7, 2024

@squareclouds sure here is my implementation:

`// custom search engine
function searchEngine(query, record) {
return record;
}

    const autoCompleteJS = new autoComplete({
        selector: "#autoComplete",
        placeHolder: "Search for your stuff",
        searchEngine: searchEngine, // Strict, loose or custom search engine
        data: {
            src: async (query) => {
                try {
                    // Fetch Data from external Source
                    const source = await fetch(`your api endpoint`);
                    const data = await source.json();
                    return data;
                } catch (error) {
                    return error;
                }
            },
            // Gets the value for the specified key from your api's response
            keys: ["my-api-value"]
        },
        resultItem: {
            highlight: true, //Does not work with custom search engine. You'll need to implement this yourself if necessary
            element: (item, data) => {
                // Here you can modify the div containing your data (item) and your data (data).
                }
            },
        },
        events: {
            input: {
                selection: (event) => {
                    // I use this for accessing the data of the result selected by the user.
                }
            }
        }
    });`

Please let me know if anything is unclear.

from autocomplete.js.

squareclouds avatar squareclouds commented on June 7, 2024

@LuViKu perfect! this worked like a charm :) you had one mistake though, after resultItem you close the whole object, you have one bracket too much

resultItem: {
            highlight: true, //Does not work with custom search engine. You'll need to implement this yourself if necessary
            element: (item, data) => {
                // Here you can modify the div containing your data (item) and your data (data).
                }
            },
        }, //  <<<-------- must be removed

from autocomplete.js.

Related Issues (20)

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.