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

Autocomplete & Ajax #5

Closed
dugi07 opened this issue May 20, 2021 · 3 comments
Closed

Autocomplete & Ajax #5

dugi07 opened this issue May 20, 2021 · 3 comments

Comments

@dugi07
Copy link

dugi07 commented May 20, 2021

Is there any better option to use JSON to recive data from other file ?

const ac = new Autocomplete(field, {
onInput: function () {
dane=AJAX(); ac.setData(dane);
},data:[{label: "Text formatu JSON", value: 42}], .....

@sp00n
Copy link
Contributor

sp00n commented May 20, 2021

I'm using the onkeyup event handler of the input field itself to set the data. But I'm not actually sure this is better than the onInput option, I've seen this only just now.

document.getElementById("myInputField").addEventListener("keyup", function(event) {
    const val = this.value;

    // Get the data from AJAX, IndexedDb, whatever
    getDataFromWhereEver(val).then(function(entries) {
        ac.setData(entries);
    });
});

@dugi07
Copy link
Author

dugi07 commented May 24, 2021

Thx for answer.

@dugi07 dugi07 closed this as completed May 24, 2021
@AgentSmith0
Copy link
Contributor

Maybe an example could be added in the README file?

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

3 participants