Selectize.js = how to stop it from auto loading remote data-source of suggestions?

Using selectize.js plugin, https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md

it seems to triger the load() function everytime I type into the input field..

I wanted to make it load once only during initialization… been at this for an hour trying to figure it out… i’ve a feeling it doesn’t have such functionality, or am I missing something?

Thanks guys…



How can I stop an auto-generated Linq to SQL class from loading ALL data?

DUPLICATE of http://stackoverflow.com/questions/2433422/how-can-i-stop-an-auto-generated-linq-to-sql-class-from-loading-all-data post answers there! I have an ASP.NET MVC project, much like the NerdD

How to prevent a datasource from loading

I have two datasource in my app-ds.xml file. I want only one to load at a time. Because loading both will take much cpu resources. It means that I will have a flag somewhere that will determine which

jQuery UI autocomplete from remote datasource example

I’m working on getting jQuery UI autocomplete to work from a remote datasource. http://jqueryui.com/demos/autocomplete/#remote The sample code calls a php script search.php $(function() { $( #birds

How can I stop an ASP.NET website from loading depending on a certain condition?

How can i stop asp.net website? I want check some condition and after that if something’s wrong then stop website from loading.

How to stop Quicktime movie in web page from auto loading?

I have two quicktime movie files embedded in one web page. I have set autoplay=false to prevent them both from playing at the same time, but they still load at the same time. Can I prevent them from

How can I stop an auto-generated Linq to SQL class from loading ALL data?

UPDATE: from what I’m hearing, I was imagining the problem I describe below. So, this is pretty much a non-question. Future readers, move on… nothing to see here. I have an ASP.NET MVC project, much

Stop iframe from loading

So i have iframe and i’m uploading files through it, so my question is how can i stop it in the middle of the loading? I’ve tried to change src with jquery function attr() but i didn’t do any good, i’

How to stop UIWebView from loading URL immediately?

I Want to stop WebPage Loading of UIWebView while passing it another URL for Loading.

How can I auto implement suggestions in Android Studio?

How can I auto implement suggestions in Android Studio just like Eclipse. Any idea? In Eclipse we can click on the suggestions so that it will get implemented by Eclipse itself. Eg. If a variable acc

How is Auto-Suggestions implemented in Android? [closed]

I am trying to see in android source code as how exactly auto-suggestion is implemented. For example, editable compose textview in messaging application shows suggestions when we start typing. I under

Answers

I had trouble working this out. The documentation is split into Usage and API.

The load option of selectize.js is used for query/response services that will return subsets of the available data depending on the query. It makes sense that it would fire each time the query changes.

Of course, this is unnecessary if your data source does not accept query parameters. In this case, a one-time load of data should be sufficient.

According to the API, you can grab the selectize instance and call a number of methods on it, including a load.

<script>
    var $select = $('#select').selectize({
        valueField: 'value',
        labelField: 'label',
        searchField: ['label']
    });

    var selectize = $select[0].selectize;

    selectize.load(function (callback) {
        $.ajax({
            url: 'http://localhost:64596/api/things',
            type: 'GET',
            error: function (e) {
                console.error(e.responseText);
                callback();
            },
            success: function (data) {
                callback(data);
            }
        });
    });
</script>

To make selectize input load only first time you can make something like this:

$('#select').selectize({
    preload: true, // make selectize load options after initialization
    load: function(query,callback){
        this.settings.load = null; // prevent selectize from loading when typing
        // also instead of this you can 
        // override this.onSearchChange = function noop(){};
        $.ajax({...}).then(function(response){
            callback(response);
        },function(){
            callback();
        }) 
    }
});