ichord / At.js

Add Github like mentions autocomplete to your application.
http://ichord.github.com/At.js
MIT License
5.3k stars 671 forks source link

Defer loading of AJAX data until @ is pressed #499

Closed edwh closed 7 years ago

edwh commented 7 years ago

Thanks for the very useful plugin, and apologies for raising an issue rather than doing an enhancement.

I'm using the option where data is a string to trigger loading of options over AJAX. In most of my comments, @ isn't used, and it would therefore reduce the load on my servers if the loading of the data was deferred until the @ key was pressed - even though this would introduce a slight user delay.

At the moment I'm doing this via a keypress event, and only instantiating your plugin once the @ key is pressed. That works fine, but it might be nice if there was an option for it.

markdon commented 7 years ago

I don't totally understand what you're after, but is sounds like you might be wanting to load the data to search/filter only after typing @ . You can do this by overriding remoteFilter with a function that requests your data from your server and passes it to callback.

Something like...

$('#inputor').atwho({
    at : "@",
    remoteFilter : function (query, callback) {
        $.getJSON(
            "/mydataurl",{}
            callback);
    },
})
edwh commented 7 years ago

Ah, thanks, I hadn't appreciated what remoteFilter does.