Configuring minimum input length / user-defined callback whether results should show #376
richardebeling
started this conversation in
Ideas
Replies: 1 comment
-
Interesting. Yeah, shouldLoad would be the obvious choice but it only effects remote data. We might need to change that. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a multi-select of names, and to prevent biases with my users, I want to only show matching results after at least 3 characters have been typed by the user.
What doesn't work
The documentation lists the
shouldLoad
callback as a potential option:However, this only limits whether
load
will be called or not here:tom-select/src/tom-select.ts
Lines 749 to 751 in 50f25e6
any options that are already loaded (in my case:
option
s of the originalselect
, so they are always loaded) will still be shown to users ifshouldLoad
returnsfalse
. (jsbin)The documentation also lists the
score
callback as a potential option:However, tom-select internally uses sifter to perform the searching/scoring, and sifter has a hardcoded path for 0-length inputs that assigns a score of 1 to each element here. Thus, I can only limit the display after the user has entered something (jsbin). For the initial dropdown, this might be solvable using
openOnFocus
, but this doesn't help if the user enters some filter and then removes it again. Also, the user can still manually open the dropdown with an empty filter.What could potentially work
Sifter provides a
limit
option that truncates results to this length. If I were able to pass in this option through tomselect, e.g. by tomselect offering aadditionalSifterOptions
setting, this could be used to limit results display in user-defined ways. I think it is suboptimal, as this is only applied after results have been scored, filtered and sorted, all of which wastes computing power if we already know that we do not want to show any results, but I guess it would work for me.Tomselect could offer some kind of callback setting that can be used to signal that no results should be shown. This could by implemented by adding a simple check here:
Conclusion
Am I missing something, is there some other way to achieve this? If not, is there a chance any of the options above could be made available to users?
Beta Was this translation helpful? Give feedback.
All reactions