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

Only fetch on typing and show results on focus #223

Closed
stell opened this issue May 18, 2021 · 4 comments
Closed

Only fetch on typing and show results on focus #223

stell opened this issue May 18, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@stell
Copy link

stell commented May 18, 2021

Hi there,
when using:

trigger: {
    event: ["input", "focus"],
},

the result fetching is done every time. But if someone only types in a few chars, fetching is done and then he removes from focus and gets back into focus the fetching is done again, without being necessary, because nothing changed.

Is it possible to only fetch on typing and display already fetched results on focus?

@stell stell added the enhancement New feature or request label May 18, 2021
@TarekRaafat
Copy link
Owner

Hello @stell,

Unfortunately, there's no way I'm aware of in the current version would help you do that.
Since all the events in the trigger.event are coupled to the input field interactions, still you might find out a workaround.

On the other hand, such behavior would be easily achievable in the new release v10 since there is an API for controlling the resultsList behavior out-of-the-box and I've added an events API as well upon receiving your issue to avail the behavior that you're looking for easier and leaner.

PS: v10 will be released within a week.

Cheers, and have a nice day! :)

@stell
Copy link
Author

stell commented May 19, 2021

Sounds nice. Will check it when 10 is out. Thanks!

@TarekRaafat
Copy link
Owner

Hello @stell,

v10.0.3 is out now and the behavior you've asked about is now easily achievable using it as shown below.

You'll just have to add focus event on input using the new events API to start the engine on focus which won't fetch the data again incase it's cached already

// autoComplete.js Config Options
events: {
    input: {
        focus: () => {
            const inputValue = document.querySelector("#autoComplete").value;

            if (input.length) autoCompleteJS.start();
        },
    },
},

Please try it and let me know how it goes. Cheers! :)

@stell
Copy link
Author

stell commented Dec 15, 2022

This works just fine:

focus() {
   // if (autoCompleteJS.input.value.length) autoCompleteJS.start();
   if (autoCompleteJS.input.value.length) autoCompleteJS.open();
},

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

2 participants