autoComplete.js icon indicating copy to clipboard operation
autoComplete.js copied to clipboard

Replace value on click

Open bacloud22 opened this issue 1 year ago • 5 comments

Hi, I cannot set the value, when the user clicks on suggestions, value of input is empty, and even the visible input does not reflect the selected (onclick) on suggestion.

Thanks a lot

bacloud22 avatar Aug 03 '24 08:08 bacloud22

Hello @bacloud23,

Can you please share more details on what you're trying to achieve and, if possible, your config file?

TarekRaafat avatar Aug 03 '24 10:08 TarekRaafat

I experience the same issue. I copied the basic steps in the docs under usage and for some reason the item is not represented in the input value when clicking on it.

https://github.com/user-attachments/assets/6e96ba86-5b1a-4542-b9a8-6ac77acbfafe

DevDuki avatar Sep 04 '24 11:09 DevDuki

Hello @DevDuki,

Can you please share your configurations?

TarekRaafat avatar Sep 05 '24 09:09 TarekRaafat

@TarekRaafat Hi thank you for your response; this is my configuration:

const autoCompleteJS = new autoComplete({
    selector: '#autoComplete',
    placeHolder: 'Recherche rapide...',
    data: {
        src: async (query) => {
            try {
                // Fetch Data from external Source
                const options = isDevEnv
                    ? { referrerPolicy: 'unsafe-url', credentials: 'include' }
                    : { credentials: 'include' }
                const source = await fetch(`localhost/autocomplete/${query}`, options)
                // Data is array of `Objects` | `Strings`
                return await source.json()
            } catch (error) {
                return error
            }
        },
    },
    cache: true,
    debounce: 300,
    searchEngine: 'loose',
    diacritics: true,
    maxResults: 15,
    threshold: 3,
    resultItem: {
        highlight: true,
    },
    events: {
        input: {
            selection: (event) => {
                const selection = event.detail.selection.value
                const keyword = selection._id
                autoCompleteJS.input.value = keyword
                window.location.href = `localhost/keyword/${keyword}`
            },
        },
    },
})

bacloud22 avatar Sep 09 '24 18:09 bacloud22

@bacloud23

Your data.src is an array of object, keys is required

selector: '#autoComplete',
placeHolder: 'Recherche rapide...',
data: {
    keys: ['_id'], // <-- just add this
    src: ......
}

Documentation Link

mgcodeur avatar Sep 12 '24 16:09 mgcodeur