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

"async" call in custom "source" function not working as expected #250

Open
OzzieIsaacs opened this issue Oct 11, 2021 · 0 comments
Open

Comments

@OzzieIsaacs
Copy link

OzzieIsaacs commented Oct 11, 2021

The problem can be seen on example "Default Suggestions" (https://typeahead.js.org/examples/#default-suggestions)

https://gist.github.com/jharding/ee0e44e70097c211070d#file-default-suggestions-html

If you remove the prefetch in Bloodhound and replace it with a remote block (I also checked it with a real server returning only valid results, same problem, so I think this is a valid example)

    // prefetch: '../data/nfl.json'
    remote: {
        url: '../data/nfl.json',
    }

You no longer get typeahead suggestions.

I could reproduce the problem with the twitter 0.11 version and also with 1.3 and newest master commit from this repository.
I tried it with Linux Mint 20.2 on "localhost" with Firefox browser.

-------------------------- End of Problem ---------------------------

-------------------------- My real problem -> only usefull to read if another solution is possible ---------------------------
My real usecase is a bit more complicated: I'm having a input field where the user is supposed to enter a list of authors with are separated by "&" and I'm doing a typeahead of each author on it's own and assembling the results author name by authorname:
Example:

Content Remote search Typeahead Result
Auth Auth Autor Name
Autor Name & Ano Ano Another Authors name

-------------------------- End of my real problem ---------------------------

-------------------------- Beginning of my solution/proposal ---------------------------

After a long search I could tear the problem to the function update in class Dataset:

update: function update(query) {
)
In following line the problem occurs according to my debugging:
if (syncCalled) { return; }

The line is called twice (At least if you enter a letter which should return something from the server) in the example (first time local suggestions, 2nd time from the remote path). The 2nd time the variable syncCalled is true, therefore the following code is not executed.

By modifying the line to:
if (syncCalled && !async) { return; }

The modification worked for me. But I honestly have to say that I don't understand how it is supposed to work, so I didn't create a PR.

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

No branches or pull requests

1 participant