Selectize.js = how to stop it from automatically loading remote data sources from offers?

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

It seems the triger function is load () every time I enter into the input field.

I wanted it to load only once during initialization ... was at this hour, trying to figure it out ... I feel that it does not have such functionality, or am I missing something?

Thanks guys...

+6
source share
2 answers

To make an input load selection only for the first time, you can do 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(); }) } }); 
+6
source

I am having trouble with this. The documentation is divided into Usage and API .

The selectize.js download function is used for request / response services that return subsets of the available data depending on the request. It makes sense that it will fire whenever a request changes.

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

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

 <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> 
+2
source

Source: https://habr.com/ru/post/971856/


All Articles