Skip to content

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

@OzzieIsaacs

Description

@OzzieIsaacs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions