question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Choices for a while and now I want to implement remote search. The list of users is over 100k, so external load and search is needed.

But it loses focus on every keystroke when typing. Please see jsfiddle example: https://jsfiddle.net/8zn132go/9/

var config = {
  'searchResultLimit': 15,
  'searchChoices': false
};
var select = document.getElementById('users');
var choice = new window.Choices(select, config);
select.addEventListener('search', function(event) {
    if (event.detail.value) {
        choice.setChoices(function(callback) {
            return fetch(
                // below api is only used for this example. it doesn't support query filtering, but its returns some data. 
                'https://randomuser.me/api/?results=20&q=' + event.detail.value
            )
            .then(function(response) {
                return response.json();
            })
            .then(function(data) {
                return data.results.map(function(user) {
                    return { value: user.login.uuid, label: user.name.first };
                });
            });
        })
    }
});

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:14

github_iconTop GitHub Comments

13reactions
jshjohnsoncommented, Jan 23, 2020

This looks like a bug - will look into this 👍

6reactions
rizkhalcommented, Dec 26, 2021

I solved it with simple code below

let choice = new Choices(element);
element.addEventListener('search', async (e) => {
    let data = await doSearch(e.detail.value);
    .then(res => {
        return res.json();
    });

    choice.setChoices(data, 'value', 'label', true);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Search Remotely – A marketplace where current and aspiring ...
Search Remotely. A marketplace where current and aspiring remote workers find new job opportunities and up-skill with online courses. Remote companies can use ......
Read more >
Remote Jobs in Today's Popular Categories - Remote.co
Remote.co's job board has openings in the most popular remote job categories. Search for the best opportunities that match your skills & career...
Read more >
FlexJobs: Best Remote Jobs, Work from Home Jobs, Online ...
The #1 job site for hand-screened remote jobs (work from home jobs) since 2007. No ads, scams or junk. Discover a better online...
Read more >
We Work Remotely: Remote jobs in design, programming ...
Find the most qualified people in the most unexpected places: Hire remote! We Work Remotely is the best place to find and list...
Read more >
The 25+ Best Sites For Finding Remote Work Online in 2022
Find the best remote work online with this convenient top 25+ remote job website list. Don't wait to find your dream job, get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found