'Require minimum filter input length with TomSelect (like select2's minimumInputLength)

I have a webpage with a multi-select field for names, and to prevent biases, I want to only show list entries to users after they have entered at least 3 characters into the filter/search field.

Select2 supports this using the minimumInputLength setting (jsbin)

What would be the best way to achieve this with TomSelect? jsbin-template for tomselect here

Their documentation lists the shouldLoad setting as a possibility, with this explanation:

Use the shouldLoad() callback to implement minimum input length or other input validation. If the callback returns false, load() will not be called and the not_loading template will be added to the dropdown instead of the loading or no_results templates.

However, it seems that shouldLoad only limits whether load() will be called to fetch additional results from the remote resource, but any results that are already available will always be shown, no matter what shouldLoad returns (jsbin mre).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source