Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace value on click #433

Open
bacloud22 opened this issue Aug 3, 2024 · 5 comments
Open

Replace value on click #433

bacloud22 opened this issue Aug 3, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@bacloud22
Copy link

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 bacloud22 added the enhancement New feature or request label Aug 3, 2024
@TarekRaafat
Copy link
Owner

Hello @bacloud23,

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

@DevDuki
Copy link

DevDuki commented Sep 4, 2024

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.

screencast.2024-09-04.13-31-37.mp4

@TarekRaafat
Copy link
Owner

Hello @DevDuki,

Can you please share your configurations?

@bacloud22
Copy link
Author

bacloud22 commented Sep 9, 2024

@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}`
            },
        },
    },
})

@mgcodeur
Copy link

mgcodeur commented Sep 12, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants