Do not detect result without result - Selectize.js

Is there a way to detect an empty search result when working with Selectize.js ?

If the user is typing something, and if he does not get the content from the drop-down list, is there a way to detect empty searches?

+4
source share
2 answers

Selectize.jshas an event with a name onType. When the user enters something, the onType event fires. You just need to register this event when you initialize Selectize.js. Then you should calculate the final results using the filter.

Here is the implementation:

$('select[name=country_id]').selectize({
      // When user type something, onType event will fire.
      onType  : function(text) {
        if ( ! this.currentResults.items.length) {
          $('#country-not-found').removeClass('hide');
        } else {
          $('#country-not-found').addClass('hide');
        }
      }
    });

For information, click on the following link:

https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md#callbacks

+4

, selectize.js onChange. , - . , "- ".

City/State Selection , , onChange. .

$select_state = $('#select-cities-state').selectize({
    onChange: function(value) {
        if (!value.length) return;
        select_city.disable();
        select_city.clearOptions();
        select_city.load(function(callback) {
            xhr && xhr.abort();
            xhr = $.ajax({
                url: 'http://www.corsproxy.com/api.sba.gov/geodata/primary_city_links_for_state_of/' + value + '.json',
                success: function(results) {
                    select_city.enable();
                    callback(results);
                },
                error: function() {
                    callback();
                }
            })
        });
    }
});
+1

All Articles