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

Fixed when empty query added as bad query in case of no results #845

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

szabto
Copy link

@szabto szabto commented Dec 25, 2022

There was an issue when empty query was ran but no result given, the code did not even try to query result when empty search did not give results.

There was an issue when empty query was ran but no result given, the code did not even try to query result when empty search did not give results.
@tkirda
Copy link
Member

tkirda commented Dec 26, 2022

Looks like that is by design, if there are no results, it would not try to query again. I don't see how it would not run a query. Did you set minChars to 0?

@szabto
Copy link
Author

szabto commented Dec 29, 2022

Sure I set it to minchars to 0. It works well, but there is a small bug.

My scenario is the following:
You click into the textbox and shows suggestions without typing anything

  • If user logged in, then it shows previously typed stuff
  • If user not logged in, and previously typed nothing, then it does nothing to show

Everything is fine, when you have previously typed stuff, so if you have results for no typed characters.
And if you don't have suggestions for 0 characters, but there are results for typed characters, then it does not try to query these results.

Currently I implemented this as a city lister and selector.
So I have previously selected cities when I type nothing.
But when I start to type, I get city name results.
But if I visit the page firstly, and I have no previously searched cities -> so 0 results, then it does nothing when I start to type.

@tkirda
Copy link
Member

tkirda commented Dec 29, 2022

What you are modifying is processResponse. That means there was a query and it is processing response.

Maybe your problem is cache? Try disabling it and see how it works.

@szabto
Copy link
Author

szabto commented Feb 6, 2023

The actual problem is here:

       isBadQuery: function (q) {
            if (!this.options.preventBadQueries){
                return false;
            }

            var badQueries = this.badQueries,
                i = badQueries.length;

            while (i--) {
                if (q.indexOf(badQueries[i]) === 0) {
                    return true;
                }
            }

            return false;
        },

If you write an empty search, and it gives no result, then it won't try to query anything else because of this q.indexOf(badQueries[i]) === 0
As soon as it ran a query with "" and gives no result, then it goes to bad queries, then it won't try to query anything, because
const str = "hello"; and str.indexOf("") will always be 0.

But maybe this is working as designed, and needs to be workarounded with always non empty result for "" search.

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

Successfully merging this pull request may close these issues.

None yet

2 participants