Selectr icon indicating copy to clipboard operation
Selectr copied to clipboard

Support for AJAX-loaded options?

Open binary-koan opened this issue 8 years ago • 3 comments
trafficstars

I don't particularly want a full-blown lazy loading framework like select2 and friends (that would be unnecessary bloat IMO), but I'd still like some way of feeding async data into a selectr box.

My idea would be to add

  • removeOption / removeAllOptions methods to go alongside addOption
  • A search event triggered when anything is typed into the search box

Then I could have something along the lines of

var selectr = new Selectr("#my-lazy-select")

selectr.on("selectr.search", query => {
  if (query.length >= 3) {
    fetch("/results.json", { body: { query } }).then(results => {
      selectr.removeAllOptions()
      results.forEach(result => selectr.addOption(result))
    })
  }
})

... or something totally different (for example, with this approach having a loading spinner would be kinda annoying).

Let me know what you think :)

binary-koan avatar Jun 23 '17 02:06 binary-koan

This is something I've mulling over for a while so it's probably time to implement it. I'll give it some time over the weekend.

Mobius1 avatar Jun 23 '17 14:06 Mobius1

Hi @Mobius1 , is this something currently working? Our team is considering using this in a project, but we need ajax support.

klaudiomilankovic avatar Oct 04 '18 13:10 klaudiomilankovic

It's currently on track, but no ETA yet. I've had to abandon some other repos to concentrate on this one.

Mobius1 avatar Oct 04 '18 18:10 Mobius1