Skip to content
Advertisement

How can I disable automatic filtering in selectize.js? Built-in / plugin / modilfy source?

I have a selectize.js drop-down, which loads a list of items from the server using ajax. The server provides an autocomplete from the given string, so I don’t need selectize’s native filtering. Besides, I really need to turn it off: The server output may be totally different from selectize’s one.

The data is fed into JavaScript objects fine, but selectize doesn’t even show a popup, since those items doesn’t match selectize’s filter. How can I disable or modify native filtering and the matches highlighting algorithm? Either with a built-in option, or with a plugin? Or is the only way to go to modify the source?

EDIT:

searchField: false / function() doesn’t work (and documentation doesn’t mention them as available option values)

EDIT2:

Eventually came up with this trick: Add a fake field to each item, assign a search string to it and tell selectize to use is as a searchField. But obviously, there should a better way, so the question is still open.

Advertisement

Answer

I needed to disable searching so iPhones won’t be displaying the keyboard. The solution I settled on makes the search field readonly by hooking into the selectize setup (without modifying the actual source, so selectize is still updatable). Here’s the code, if anybody needs it:

// Put this code after you've included Selectize
// but before any selectize fields are initialized
var prevSetup = Selectize.prototype.setup;

Selectize.prototype.setup = function () {
    prevSetup.call(this);

    // This property is set in native setup
    // Unless the source code changes, it should
    // work with any version
    this.$control_input.prop('readonly', true);
};
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement