Selectr
Selectr copied to clipboard
Support for AJAX-loaded options?
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/removeAllOptionsmethods to go alongside addOption- A
searchevent 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 :)
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.
Hi @Mobius1 , is this something currently working? Our team is considering using this in a project, but we need ajax support.
It's currently on track, but no ETA yet. I've had to abandon some other repos to concentrate on this one.